Skip to content

Instantly share code, notes, and snippets.

@Dalmirog-zz
Forked from PaulStovell/ADTest.ps1
Last active November 9, 2015 18:37
Show Gist options
  • Save Dalmirog-zz/370a79255ef76558aff5 to your computer and use it in GitHub Desktop.
Save Dalmirog-zz/370a79255ef76558aff5 to your computer and use it in GitHub Desktop.
$usernameToFind = "DOMAIN\USERNAME"
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$contextType = [System.DirectoryServices.AccountManagement.ContextType]::Domain
$context = New-Object System.DirectoryServices.AccountManagement.PrincipalContext -argumentlist ($contextType)
$user = [System.DirectoryServices.AccountManagement.UserPrincipal]::FindByIdentity($context, $usernameToFind)
Write-Output $user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment