PowerShell Tips: Retrieving The Distributions Lists A User Is A Member Of

Lets say you have a user and want to get all the distribution lists this user is a member of. Well the following PowerShell script can help you with that. First you will require a remote Exchange shell for this as detailed during the 20:38 minute of the following video:

Next, utilize the following PowerShell script:

Line 1 declares the variable to hold the DistinguishedName attribute for the user of interest. Line 2 competes the grunt work of searching. This gets all the distribution groups which have a member equal to the DN of the user of interest.

The above script positions the Distribution Groups return into a Select-Object cmdlet to report the Name property and then a custom column. The label is Members and the content is going to just be a string of all the Distribution Group members’ names separated by semicolons. The expression for my custom column is a Get-DistributionGroupMember command for the Distribution Group piped into a Foreach-Object (alias is “%”) which returns an array of all the names of the members in the Distribution Group. I use the -join command to take the array and convert it into a string separated by semicolons.

When Get-DistributionGroup is utilized, you do not get the members of that group back with it. Here are the properties that come back that contain the string mem in the name.

Nothing in there contains the members and so the initial script provided in this post is utilized.

Comments (0)

Skip to main content