Skip to content

Instantly share code, notes, and snippets.

@aaronpmiller
Created July 17, 2015 04:26
Show Gist options
  • Save aaronpmiller/28bee4f94974f291d287 to your computer and use it in GitHub Desktop.
Save aaronpmiller/28bee4f94974f291d287 to your computer and use it in GitHub Desktop.
Function Get-ADNestedMemberOf ($userName) {
# For a specified user get the groups it is a member of recursively.
$targetUser = Get-ADUser $userName
$results = Get-ADGroup -Filter {member -RecursiveMatch $targetUser.DistinguishedName}
return $results
}
Function Test-ADIsMember ($objectDN, $groupDN) {
# params require full DistinguishedName
# Generalized for any ADObject and the return is the not null test. This Will produce the same errors as the standard IsMember if either object doesn't exist
(Get-ADObject -Filter {memberOf -RecursiveMatch $groupDN} -SearchBase $objectDN -SearchScope Base) -ne $null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment