This function will recursively enumerate members of a given group along with nesting level and parent group information. If there is a circular membership, it will be displayed in Comment column.

It accepts input from pipeline and works well with get-adgroup. I personally use it with Format-Table or Export-Csv to get output in a tabular form.

When used with an -indent switch, it will display only names, but in a more user-friendly way (sort of a tree view)


If you have an idea how to improve it, don't hesitate to let me know.

Author: Piotr Lewandowski 
Version: 1.01 (04.11.2014) 
Get nested group membership from a given group or a number of groups. 
Function enumerates members of a given AD group recursively along with nesting level and parent group information.  
It also displays if each user account is enabled.  
When used with an -indent switch, it will display only names, but in a more user-friendly way (sort of a tree view)  
Get-ADNestedGroupMembers "MyGroup1", "MyGroup2" | Export-CSV .\NedstedMembers.csv -NoTypeInformation 
Get-ADGroup "MyGroup" | Get-ADNestedGroupMembers | ft -autosize 
Get-ADNestedGroupMembers "MyGroup" -indent 
"MyGroup1", "MyGroup2" | Get-ADNestedGroupMembers  -indent