You have quite a few questions regarding nested groups.
Here's a function that show nested groups and their offsets.
It will also deal with circular references.
It would take some effort to get it into the format that you have requested.
function Get-NestedGroups {param ($strGroup,$Offset) $currentGroupGroups = (Get-ADGroup Identity $strGroup Properties Memberof).Memberof ForEach ($memGroup in $currentGroupGroups) { If ($script:groupList.ContainsKey($memgroup) -eq $False) { $strMemGroup = ($memGroup -split ",*..=")[1] $script:GroupList[$memGroup] = $True "$Offset$strMemGroup" Get-NestedGroups -strGroup $strMemGroup $($Offset + ".") } Else { "$Offset$strMemgroup Circular Reference" } } } # Hash table to track group memberships. $groupList = @{} Get-NestedGroups TestGroup
- Edited by Newbie Jones 21 hours 33 minutes ago