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.

PowerShell
Edit|Remove
<#   
.SYNOPSIS 
Author: Piotr Lewandowski 
Version: 1.01 (04.11.2014) 
Get nested group membership from a given group or a number of groups. 
 
.DESCRIPTION 
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)  
    
.EXAMPLE    
Get-ADNestedGroupMembers "MyGroup1", "MyGroup2" | Export-CSV .\NedstedMembers.csv -NoTypeInformation 
 
.EXAMPLE   
Get-ADGroup "MyGroup" | Get-ADNestedGroupMembers | ft -autosize 
             
.EXAMPLE              
Get-ADNestedGroupMembers "MyGroup" -indent 
  
.EXAMPLE              
"MyGroup1", "MyGroup2" | Get-ADNestedGroupMembers  -indent 
#>