Skip to content

Instantly share code, notes, and snippets.

@aaronpmiller
Created July 17, 2015 04:26
Show Gist options
  • Select an option

  • Save aaronpmiller/28bee4f94974f291d287 to your computer and use it in GitHub Desktop.

Select an option

Save aaronpmiller/28bee4f94974f291d287 to your computer and use it in GitHub Desktop.

Revisions

  1. aaronpmiller created this gist Jul 17, 2015.
    12 changes: 12 additions & 0 deletions RecursiveADMembers.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    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
    }