This article helps you to query nested AD group members using powershell. We can get group members by using the Active Directory powershell cmlet Get-ADGroupMember. The Get-ADGroupMember cmdlet provides the option to get all the nested group members by passing the parameter -Recursive. This powershell script also handles circular membership (infinite loop) problem.
Import-Module ActiveDirectory function Get-ADNestedGroupMembers { [cmdletbinding()] param ( [String] $Group ) Import-Module ActiveDirectory $Members = Get-ADGroupMember -Identity $Group -Recursive $members } Get-ADNestedGroupMembers "Domain Admins" | Select Name,DistinguishedName
Export Nested Group Members to CSV
We can export the nested group members output to csv file by using the powershell cmdlet Export-CSV.
Import-Module ActiveDirectory function Get-ADNestedGroupMembers { [cmdletbinding()] param ( [String] $Group ) Import-Module ActiveDirectory $Members = Get-ADGroupMember -Identity $Group -Recursive $members } Get-ADNestedGroupMembers "Domain Admins" | Select Name,DistinguishedName | Export-CSV "C:\ADNestedGroupMembers.csv" -NoTypeInformation -Encoding UTF8
Advertisement