Large distribution groups can lead to some unfortunate incidents in an Exchange organization, such as the one that occurred at Reuters recently when a person was able to send to 33,000 recipients, causing a server-crushing increase in email traffic as hundreds of those recipients proceeded to “reply all”.
One of the precautionary measures you can take is restricting who can send to your largest distribution groups. Of course this means you must first identify those groups, which is quite simple to do with PowerShell.
The Exchange management shell includes a Get-DistributionGroupMember cmdlet that can output the members of a distribution group. This cmdlet has one flaw in that it does not perform a recursive search. For example, this “All Staff” distribution group has two smaller groups nested in it as members, which then contain the several hundred individual recipients. If we use Get-DistributionGroupMember it tells us that there are two members, which is true in one sense, but quite useless for our objective here.
[PS] C:Scripts>(Get-DistributionGroupMember "All Staff").Count 2
Sure, we could build a script with a recursive function that expands the membership of any groups contained within other groups, and that would do the job. But that’s a bunch of code that isn’t necessary, because fortunately an Active Directory PowerShell cmdlet comes to the rescue. Get-ADGroupMember has a -Recursive switch to handle this for us.
[PS] C:Scripts>(Get-ADGroupMember -Recursive "All Staff").Count 389
So let’s say that we want to produce a report of all distribution groups that contains their names, member counts, and managers as well (in case we need to discuss any restrictions on the group with the owner/manager). I’ve written a simple PowerShell script to do just that.
Download Get-DGMemberCounts.ps1 from Github
Here’s an example of the script running.
[PS] C:Scripts>.Get-DGMemberCounts.ps1 Payroll Team has 3 members Public Folder Owners has 2 members Head Office Staff has 386 members All Staff has 389 members Regional Office Staff has 4 members All Office Meeting Rooms has 3 members Deny Outgoing External Email has 1 members ZTestExternal2 has 1 members Security Team has 0 members Social Club has 3 members App_Tier2_ABCDEF has 1 members DL_Alannah.Shaw has 2 members DL_Mike.Ryan has 2 members DL_ex2010test has 1 members
And the resulting CSV file.