Get distribution group all members – nested

This post is also available in: Polish

How can we get a list of mailboxes belonging to a distribution group?
In a simple way, by using the EMC console and check who is a member of a group, or by using powershell EMS console and use the command:

Get-DistributionGroupMember Test_Group

 

In this way we get a list of objects in the group, both mailboxes, contacts, and other groups.

And here there is a problem, because if the distribution group includes the next distribution group, and this again next etc, how can we get a list of all people who receive an email after sending a message to a distribution group?

Unfortunately, using only the Get-DistributionGroupMember we won’t get such information.

This command returns only the objects directly in a group, without nesting.

In this case, we have to use PowerShell commands for Active Directory available.

To do this run EMS console and import the Active Directory module command as follows:

import-module ActiveDirectory

 

Now we can use:

Get-ADGroupMember Test_Group

 

However, in this case also we only get a list of objects that are directly in the group Test_Group.

To get a list of all the objects that are in the group, including nested objects that are located in other distribution groups that are members of Test_Group, we need to use the -Recursive parameter.

 

Get-ADGroupMember Test_Group -Recursive

 

In this way we obtain a list of all objects in the group including nested objects.

If you want to know how many of these objects, simply type:

$(Get-ADGroupMember Test_Group -Recursive).count

 

To get a list of all users in the group whose accounts are disabled in Active Directory we can use the command as follows:

Get-ADGroupMember Test_Group -recursive | % {Get-ADUser $_ -properties enabled | ? {$_.enabled -eq $False} | select Name}

 

In this way we get a list of people who have a disabled account in Active Directory, and perhaps they should not have to belong to a group Test_Group.

 

Print Friendly
Tagged , , , , . Bookmark the permalink.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>