All exchange admins working for bigger firms are familiar with large number of distribution groups present in the exchange environment. Sometimes different departments put the request for new distribution groups to be created, but will be used rarely or not at all. At times, the groups will be empty as well, either because the members have left the company or it was never populated.
How can we find out the distribution groups which doesn’t have any members in it? Powershell to the rescue. Run
Get-DistributionGroup | Where-Object { (Get-DistributionGroupMember –identity $_.Name).Count –lt 1 }
In order to output the name and primarysmtpaddress of empty distribution groups in a nicely formatted table, run
Get-DistributionGroup | Where-Object { (Get-DistributionGroupMember –identity $_.Name).Count –lt 1 } | ft name, primarysmtpaddress -wrap
As always, you can get the output in a txt,csv or html file.
Get-DistributionGroup | Where-Object { (Get-DistributionGroupMember –identity $_.Name).Count –lt 1 } | ft name, primarysmtpaddress –wrap | Out-File c:emptygroups.txt
Yes! This is what I was looking for as .count counts members if >2. Thanks. Leo.
Yes! This is what I was looking for as .count counts members if >2.
I refer to: ([array](Get-DistributionGroupMember –identity $_.Name)).Count
Thanks. Leo.
Glad that the post helped you Leo.
Thanks.
HI!
Similar but different problem: How to find all the groups a certain user is a member of?
HI!
I have a different problem connected to this groups: I would like to find all the distribution groups one user is a member of – how can I get a list of this groups?
Thanks,
Borut
sorry. there's a missing set of parentheses in my previous post:
([array](Get-DistributionGroupMember –identity $_.Name)).Count
The "." is more tightly bound than the typing.
You should change the get-distributiongroupmember to use $_.distinguishedname.
In most cases, the "Name" property will be unique, but there's no guaranty that it is always the case. If the "Name" property matches multiple groups there'll be an error thrown. Using the DN avoids that problem.
The problem with groups having only a single member is that the cmdlet returns a scalar (which has no 'count').
Coerce the result to be an array, even if it has just one member, and you should get the script to work correctly:
[array](Get-DistributionGroupMember –identity $_.Name).Count
Hi Anonymous,
It shouldn't do that, as the cmdlet says to find groups with members less than 1. You can change it to "equal to zero" and try.
This is exactly what i am looking to do but the script is returning groups with 1 member as well which is not good.