1

The below commands will extract all the Distribution groups I own.

Get-DistributionGroup -ManagedBy James.smith@jesus.com | Export-Csv -Path c:\temp\test.csv -NoTypeInformation

Question: How can I expand this so that it it outputs all the members for each group that I own like the examples listed below.

Group1

  • member 1 - email address
  • member 2 - email address

Group 2

  • member 1 - email address
  • member 2 - email address

and so forth!

I checked online and going bat crazy, and help appreciated

1
  • You'll need to use the Get-DistributionGroupMember cmdlet.
    – jfrmilner
    Jul 19 at 15:10

1 Answer 1

1

The PowerShell #1 solution will dump the name of the member and name of the group into one csv file and more accurately matches the example logic you provided.

This solution uses select-object to add a calculated property providing the distribution group name field and value into the csv file. The variable is used to set the group name per the Get-DistributionGroup output, but before the Get-DistributionGroupMember is run and piped.

PowerShell #1

Get-DistributionGroup -ManagedBy James.smith@jesus.com  | ForEach-Object { 
   $DGName = $_.Name;
   Get-DistributionGroupMember -Identity $_.Name } |  
       Select Name, RecipientType, @{ N='Group Name'; E={$DGName};} |
        Export-Csv -Path "c:\temp\test.csv" -NoTypeInformation;

The PowerShell #2 solution that will dump the name of the member into a csv file with the name of the group as the base name of the csv file specified.

This solution works similar to setting the name of the distribution group as a variable as in the first solution, but it will use that to set the base name of the exported csv file to the value. So you'll get one file per group with this solution.

PowerShell #2

Get-DistributionGroup -ManagedBy James.smith@jesus.com | ForEach-Object {
    $DGName = $_.Name;
    Get-DistributionGroupMember -Identity $_.Name } | 
        Export-Csv -Path "c:\temp\$DGName.csv" -NoTypeInformation;

Supporting Resources

2
  • @SSP Let me know if there is something missing or needed further from the exported data. Getting more data is just a trivial matter and won't take me much time to help you determine logic adjustment should something further be needed there. Just let me know and I am happy to help you get this further solidified if required. Jul 20 at 4:47
  • 1
    This is perfect thank you, Solution 1 is perfect, means we can create a power bi report based on 1 export!
    – SSP
    Jul 20 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.