List all exchange distributiongroup members and types

This is a quick blog post on how to list exchange distribution groups for your entire exchange environment. The post is specifically written for exchange server 2010.

Lets fire up powershell ISE and start coding!

Load the powershell snapin for Exchange.

. 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'

Connect to the exchange server.

Connect-ExchangeServer -auto

Create a loop to populate a list of groupnames and groupmembers.

$groupmembers = foreach ($group in Get-DistributionGroup){ 
get-distributiongroupmember $group | select Name,@{n='Member';e={$group.name}},recipienttype
}
$groupmembers

This code does the following:

Get the memebers of each distributiongroup

foreach ($group in Get-DistributionGroup){ 
get-distributiongroupmember $group

Select the Name of the group, create an array with value member and $Group.name get the recipienttype of the member.

| select Name,@{n='Member';e={$group.name}},recipienttype}

This will create the following output:

distribution groups
powershell distribution groups

You can see the 3 fields: Name, Member and RecipientType.

  • Name: The username of the member of the group
  • Member: The group the user is a member of
  • RecipientType: what is the type of recipient (Name) This can be a Usermailbox, Group, User,….

If you want the results in a csv file, you just add the following at the end of the script.

$groupmembers | export-csv C:\Temp\mailboxgroupmembers.csv -NoTypeInformation

this exports the output as a csv to a fileĀ  C:\Temp\mailboxgroupmembers.csv

-NoTypeInformation : don’t show the first line with typeinformation in the csv file.

So there you go, now you have a list with all the members of all the exchange distribution lists.

full code:

. 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'
Connect-ExchangeServer -auto

 $groupmembers = foreach ($group in Get-DistributionGroup){ 

get-distributiongroupmember $group | select Name,@{n='Member';e={$group.name}},recipienttype

}

$groupmembers | export-csv C:\Temp\mailboxgroupmembers.csv -NoTypeInformation

Leave a Reply

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