Answered by:
Exchange 2007 - enumerate distribution lists members

Question
-
Hi All
I have approximately 600 distribution lists on an Exchange 2007 SP1 and I have to list the members of each group and export it to a csv or excel file.
Is there any quick way of doing this, maybe in powershell?
Thanks
Wednesday, November 26, 2014 12:56 PM
Answers
-
Hi,
I have some tests in my environment using Exchange 2007, you can use the following cmdlet to get all the distribution groups and their members and then export them to a csv file.
$groupmembers = foreach ($group in Get-DistributionGroup) { get-distributiongroupmember $group | select Name,@{n='DistributionGroupName';e={$group.Name}} }
$groupmembers | Export-Csv C:\DGgroupmembers.csv -NoTypeInformationHope this can be helpful to you.
Best regards,
Amy Wang
TechNet Community Support- Marked as answer by Ivan Davids Thursday, November 27, 2014 6:47 AM
Thursday, November 27, 2014 6:06 AMModerator
All replies
-
I believe Exchange 2007 still has the Get-DistributionGroupMember command, so you would run the following:
Get-DistributionList | Sort Name | Get-DistributionGroupMember
In order to map all group to their members, try the following:
Get-DistributionList | Sort Name | % { $DlName = $_.Name ; Get-DistributionGroupMember $_ | Select @{E={ $DlName };L='DlName' } }, * | Export-Csv DlMembers.csv -NoTypeInformation
That is a single line of PowerShell code - you should be able to copy it and ruin it as-is. If you don't include the $DlName = $_.Name bit, you will get the members but not the DLs they belong to. HTH ...
Wednesday, November 26, 2014 1:50 PM -
Thanks for your response, I will try it out and let you know the outcome.
Wednesday, November 26, 2014 1:55 PM -
Hi,
I have some tests in my environment using Exchange 2007, you can use the following cmdlet to get all the distribution groups and their members and then export them to a csv file.
$groupmembers = foreach ($group in Get-DistributionGroup) { get-distributiongroupmember $group | select Name,@{n='DistributionGroupName';e={$group.Name}} }
$groupmembers | Export-Csv C:\DGgroupmembers.csv -NoTypeInformationHope this can be helpful to you.
Best regards,
Amy Wang
TechNet Community Support- Marked as answer by Ivan Davids Thursday, November 27, 2014 6:47 AM
Thursday, November 27, 2014 6:06 AMModerator -
Hi Amy
This worked really well, thanks for your time and assistance
Thursday, November 27, 2014 6:47 AM -
HI Willard
I get the following when I ran as is.
[PS] C:\Windows\system32>Get-DistributionList | Sort Name | % { $DlName = $_.Name ; Get-DistributionGroupMember $_ | Select @{E={ $DlName };
tion
The term 'Get-DistributionList' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of
is correct and try again.
At line:1 char:21
+ Get-DistributionList <<<< | Sort Name | % { $DlName = $_.Name ; Get-DistributionGroupMember $_ | Select @{E={ $DlName };L='DlName' } }, *
+ CategoryInfo : ObjectNotFound: (Get-DistributionList:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Thursday, November 27, 2014 7:11 AM -
Sorry, change 'Get-DistributionList' to 'Get-DistributionGroup' in the command ...Friday, November 28, 2014 12:52 PM