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.

#Grab the Distribution Groups
$DLs=Get-DistributionGroup -resultSize Unlimited
foreach ($DL in $DLs) {
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"
#Export the file to a CSV
$DLCount|Export-Csv -Path C:\output\DLMemberCount.csv -NoTypeInformation

No comments:

Post a Comment