Hi,
Assuming you have a csv/txt file like this:
name
user1
user2
administrator
Run the following script in EMS:
$names= Import-Csv c:\temp\name.csv
$Result= @()
$groups= Get-DistributionGroup
foreach ($name in $names) {
foreach($group in $groups){
$members= Get-DistributionGroupmember $group
foreach ($member in $members){
if ($member.name -eq $name.name){
$Result1 = New-Object PSObject
$Result1 | Add-Member NoteProperty -Name "User" -Value $name.name
$Result1 | Add-Member NoteProperty -Name "group" -Value $group
$Result += $Result1
}}}}
$Result|Export-csv -Path c:\temp\result.csv -NoTypeInformation
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.