Last active
December 18, 2015 14:39
-
-
Save rycuda/00facfba6ab2de77ef5a to your computer and use it in GitHub Desktop.
Powershell snippet to recurse AD group membership, returning a complete list of users.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function recurse-ADmembership { | |
param( | |
[parameter(ValueFromPipeline=$true)][Microsoft.ActiveDirectory.Management.ADGroup]$group, | |
[Alias('groups')][hashtable]$_expandedgroups=@{} | |
) | |
process{ | |
$group | get-adgroupmember | foreach-object { | |
if (($_.objectclass -eq 'group') -and (-not $_expandedgroups.ContainsKey($_.DistinguishedName))) { | |
$_ | recurse-ADmembership -groups $_expandedgroups | |
$_expandedgroups.add($_.DistinguishedName,$true) | |
} elseif ($_.objectclass -eq 'user') { | |
$_ | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hmm, should probably change this so that it can do computers as well at some point.