Home ยป PowerShell ยป Get AdGroupMember Multiple Groups in Powershell

Get AdGroupMember Multiple Groups in Powershell

Using the Get-AdGroupMember cmdlet with parameter Recursive, we can get adgroupmember from multiple groups in the active directory.

The Get-AdGroupMember cmdlets get members of an active directory group. A group contains multiple child groups in it and using the Recursive parameter, it gets all multiple group members.

In this article, we will discuss how to get adgroupmember from multiple groups in PowerShell using the Get-AdGroupMember cmdlet.

Get AdGroupMember from Multiple Groups

To get adgroupmember from multiple groups, use the Get-AdGroupMember cmdlet with the Recursive parameter.

$adgroups = "DL-SALES", "EU-SALES", "FINANCE"

$results = @();

foreach ($group in $adgroups) 

{
   $results+= (Get-ADGroupMember -Identity $group -Recursive)

}

$results | Format-Table -AutoSize

In the above PowerShell script, the $adgroups variable stores the adgroup name and we declared the $results variable to store the members of multiple groups.

Using the foreach loop over the $adgroups, the Get-AdGroupMember uses the Identity parameter to get members of a group recursively using the Recursive parameter and stores the members of multiple groups in the $result variable.

To display the output of adgroup members in the table, we have used Format-Table -Autosize the adjust the column widths.

The output of the above PowerShell script to get adgroupmember of multiple groups is:

Get AdGroupMember of Multiple Groups
Get AdGroupMember of Multiple Groups

Cool Tip: How to get adgroupmember name and email address in PowerShell!

Conclusion

I hope the above article on how to get adgroupmember from multiple groups using the Get-AdGroupMember cmdlet is helpful to you.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.