Skip to content

Instantly share code, notes, and snippets.

@jonchampagne
Created October 13, 2019 13:59
Show Gist options
  • Save jonchampagne/37d96bfde6e11e62e31399d79c1e5cb2 to your computer and use it in GitHub Desktop.
Save jonchampagne/37d96bfde6e11e62e31399d79c1e5cb2 to your computer and use it in GitHub Desktop.
Recursively get all groups an active directory user or group is a part of
function Get-ADMembershipRecursive($name){
$names = [System.Collections.ArrayList]@()
Get-ADPrincipalGroupMembership -Identity $name | ForEach-Object {
$names.Add($_.Name) | Out-Null
Get-MembershipRecursive -name $_ | ForEach-Object {
$names.Add($_) | Out-Null
}
}
return $names
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment