Script to list The Members of Nested Distribution Groups

Connect to Exchange Online PowerShell

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session

Get list of all distribution groups

$groups = Get-DistributionGroup -ResultSize unlimited

Loop through each group and get its members

foreach ($group in $groups) {
Write-Host “Group: $($group.Name)”
$members = Get-DistributionGroupMember -Identity $group.Name -ResultSize unlimited
foreach ($member in $members) {
Write-Host “Member: $($member.Name)”

Disconnect from Exchange Online PowerShell

Remove-PSSession $Session


This script first connects to Exchange Online PowerShell using the New-PSSession cmdlet and your Office 365 credentials. It then uses the Get-DistributionGroup cmdlet to get a list of all distribution groups in your organization.

For each group, the script uses the Get-DistributionGroupMember cmdlet to get a list of its members, including members of any nested distribution groups. It then loops through each member and writes their name to the console.

Finally, the script disconnects from Exchange Online PowerShell using the Remove-PSSession cmdlet.

Note that this script assumes that you are using Exchange Online PowerShell to manage your Office 365 distribution groups. If you are using an on-premises Exchange Server, you may need to modify the script to use the appropriate cmdlets and connection settings.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a website or blog at

Up ↑

%d bloggers like this: