Skip to content

Instantly share code, notes, and snippets.

@tomorgan
Created March 1, 2013 14:25
Show Gist options
  • Save tomorgan/5064973 to your computer and use it in GitHub Desktop.
Save tomorgan/5064973 to your computer and use it in GitHub Desktop.
Function Get-UserPrincipal($userName)
{
$dsam = "System.DirectoryServices.AccountManagement"
$rtn = [reflection.assembly]::LoadWithPartialName($dsam)
$cType = "domain" #context type
$iType = "DistinguishedName"
$dsamUserPrincipal = "$dsam.userPrincipal" -as [type]
$principalContext = new-object "$dsam.PrincipalContext"($cType,$RootDomain)
Write-Host Looking for DN $UserName in Container $principalContext.Name
$a = $dsamUserPrincipal::FindByIdentity($principalContext,$iType,$userName)
Write-Host Result: $a
return $a
} # end Get-UserPrincipal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment