Get all groups an user is member of.

Sometimes it’s good to know which AD-groups a user is member of, sure it’s easy to look in the ADUC and look at the “Member of” tab… But that doesn’t tell the full story since a group can be member of another group.

Here’s a nice function I wrote which finds the groups the user is member of and all Nestled groups aswell.

You need to have the ActiveDirectory module loaded.

function Get-GroupMembership
        [Parameter (Mandatory=$true)]       
        [int]$Nested = 0    
    foreach( $temp in (Get-ADPrincipalGroupMembership ($User) -ErrorAction SilentlyContinue))    
        while ( $n -lt $Nested )        
        Write-Host $space $        
        Get-GroupMembership -User $temp.SamAccountName -Nested $Nested        

Use the function like this

Get-GroupMembership -User fbarrud

And my example output

 Domain Users
	 Normal Users
 Domain Admins
	 Denied RODC Password Replication Group

If you have any suggestions or questions, don’t hesitate to leave a comment 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *