Monday, February 11, 2013

Distribution Group Membership Count Report

A request came across my desk to generate a report of the number of people in each distribution group in the environment.

Here's what I cooked up. Quick, dirty and gets the job done.

$i=0
$y=0
$DLCount=@()
#Grab the Distribution Groups
$DLs=Get-DistributionGroup -resultSize Unlimited
foreach ($DL in $DLs) {
$y++
$i++
if ($y -eq 50) {Write-Output ("Checked {0} of {1} Distribution Group" -f $i, $DLs.Count);$y=0}
#Grab all members of the DL and count them
$count=((Get-DistributionGroupMember -Identity $DL -ResultSize Unlimited)|Measure-Object).count
#Modify the DL object so it can be added to the report collection
$DL=$DL|Select-Object Name, "MemberCount"
$DL.MemberCount=$count
$DLCount+=$DL
}
#Export the file to a CSV
$DLCount|Export-Csv -Path C:\output\DLMemberCount.csv -NoTypeInformation

No comments:

Post a Comment