We need a print out of members of all distribution groups by group.

We have an Microsoft Exchange 2013 server.   We need a print out of members of all distribution groups by group.  Is there a powershell command that will export such a listing to a .csv file.
DgreenbaumAsked:
Who is Participating?
 
SubsunConnect With a Mentor Commented:
Get-ADUser will only give the user information, to get the distribution groups and it's members, run the following script from Exchange Management Shell.
$Groups = Get-DistributionGroup -ResultSize Unlimited
$(ForEach ($group in $Groups){
$Group | Get-DistributionGroupMember -ResultSize Unlimited |
  Select @{N="GroupName";E={$Group.DisplayName}},`
		@{N="User";E={$_.DisplayName}},PrimarySmtpAddress
}) | Export-CSV C:\Group.csv -nti

Open in new window

0
 
Sean FitzpatrickSr Lab Systems EngineerCommented:
You can use Get-ADUser and Export-Csv cmdlets like below:

Get-ADUser -Filter * -SearchBase "ou=Ou,dc=contoso,dc=com" -Properties * | Export-Csv  "c:\somefile.csv"

The parameter "-Filter" is used to specify the query string, "-SearchBase" to specify an Active Directory path to search under and the "-Properties" to specify user's properties you want to export.

Details please go to:
http://technet.microsoft.com/en-us/library/ee617241.aspx

In your case you would be searching by the group that you are looking for, then just change the filter to separate each group into a .csv; or you could broaden your search filter to grab all groups.
0
 
Joshua GrantomConnect With a Mentor Systems AdministratorCommented:
Boom, Subsun beat me to it.

Except, I would change Export-CSV C:\Group.csv -nti

to

Export-CSV "C:\$Group.csv" -nti

So you have the name of the Distribution Group in the CSV Filename.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
DgreenbaumAuthor Commented:
Thanks Subsun!   We will test this and report back.
0
 
Sean FitzpatrickSr Lab Systems EngineerCommented:
Ah, thanks for the correction subsun!
0
 
DgreenbaumAuthor Commented:
The script worked well.  Thank you all.
0
All Courses

From novice to tech pro — start learning today.