Office365 Export Distribution List & Members

Every so often IT has to check group memberships on Exchange Online. This is easily doable from the interface but very time-consuming. To get around this we use scripts to drop the information in Spreadsheet format where we can do a few tricks to get the information quickly.

To do this you are required to connect to MS Office 365 Exchange Online. Once connected you can run the below script to drop the information in a Set location for Review.

The Code

$CSVPath = "C:\Temp\DistributionGroup.csv"

#Get All Office 365 Distribution Groups
$O365DistGroups=Get-DistributionGroup
ForEach ($Group in $O365DistGroups)
{

#Get Group Members and export to CSV
Get-DistributionGroupMember –Identity $Group.PrimarySmtpAddress | Select-Object @{Name="Group Name";Expression={$Group.DisplayName}},
@{Name="User Name";Expression={$_.DisplayName}}, PrimarySmtpAddress | Export-CSV $CSVPath -NoTypeInformation -Append
}

What you need to know about the code

The code for the most part is easily readable so there is not much need to say. The only thing to note is that when gathering the information from the Distribution group it uses the PrimarySMTPAddress. This is because using the NAME can conflict with groups created in Teams with the same NAME.

********************************************************

If you liked what you read Please Share.
I’d love it if you followed me on YouTube and Facebook.

Also, feel free to subscribe to my posts by email.
Donations for the site can be made here.
Thanks for reading.

Spread the love

1 thought on “Office365 Export Distribution List & Members”

Leave a Reply

Your email address will not be published. Required fields are marked *