Task – Find Empty Distribution Groups In Exchange 2007…

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…

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

10 Comments

  1. Yes! This is what I was looking for as .count counts members if >2. Thanks. Leo.

    1. 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.

    2. Rajith Enchiparambil says:

      Glad that the post helped you Leo.

      Thanks.

  2. Anonymous says:

    HI!

    Similar but different problem: How to find all the groups a certain user is a member of?

  3. 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

  4. Anonymous says:

    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.

  5. Anonymous says:

    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.

  6. Anonymous says:

    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

  7. Rajith Jose Enchiparambil says:

    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.

  8. Anonymous says:

    This is exactly what i am looking to do but the script is returning groups with 1 member as well which is not good.

Leave a Reply

Your email address will not be published. Required fields are marked *