Forum Discussion

mfranhind115's avatar
mfranhind115
Brass Contributor
Aug 26, 2022
Solved

powershell: how to get members of a distribution list

Hi all, my company have several domains under its tenant.   Now I should get, for each domain under the tenant, the list of the members of every dsitribution list.   if too hard, for me would be...
  • LainRobertson's avatar
    LainRobertson
    Aug 27, 2022

    I should have added this before posting above.

     

    If you wanted to flatten the output into a very basic CSV file rather than do further work with the objects, you can do it like this:

     

    .\Get-ExoDistributionListMembers.ps1 |
        ForEach-Object {
            $Group = $_;
    
            $Group.Members |
                ForEach-Object {
                    $_ | Select-Object -Property @{n="GroupType"; e={ $Group.GroupType}}, @{n="GroupName"; e={ $Group.GroupName}}, MemberType, MemberAddress;
                }
        } | Export-Csv -Path ".\distributionLists.csv" -NoTypeInformation;

     

    Cheers,

    Lain