Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Displaying a nested group hierarchy

$
0
0

I have an organization that loves nested groups in Active Directory.  I have found that nested groups can easily get out of control without good business practices and excellent documentation. 

I have been using Get-ADGroupMember to list the members of an AD group.  The -recursive switch listing all members.  It does however list child groups as it passes through the hierarchy.  To display these group I have a function: 

function Get-GroupHierarchy ($searchGroup)
{
import-module activedirectory
$groupMember = get-adgroupmember $searchGroup | sort-object objectClass -descending
   foreach ($member in $groupMember)
    {Write-Host $member.objectclass,":", $member.name;
    if ($member.ObjectClass -eq "group")
        {Get-GroupHierarchy $member.name}}
}


Viewing all articles
Browse latest Browse all 8583