May 27, 2014

Exchange - Distribution lists report

There is one drawback using Get-DistributionGroupMember script. Actually when you run it in a pipe for multiple distribution groups you can't determine in what group member is.

I would like to present wonderful PowerShell script that generates good report. This report have following fields: Distribution Group Name, SamAccountName and primary smtp address of distribution list, Name of user, Samaccountname, recipient type, primary smtp address of member.

I found it very useful in exchange infrastructure migration/consolidation processes. 

Here is syntax:

$R=@()
$G=Get-DistributionGroup
$G| foreach{
$GN=$_.Name
$GSAN=$_.Samaccountname
$GADDR=$_.primarysmtpaddress
$RT=Get-distributionGroupMember -identity $_.identity | select @{Name='Distribution Group'; Expression={[String]::join(";", $GN)}}, @{Name="DL SAN"; Expression={[String]::join(";", $GSAN)}},@{Name="DL PrimarySmtpAddress"; Expression={[String]::join(";", $GADDR)}}, Name, samaccountname,RecipientType,PrimarySmtpAddress
$R=$R+$RT
}
$R| export-csv DL-Report.csv

No comments:

Post a Comment