Skip to content

Instantly share code, notes, and snippets.

@clly
Created April 12, 2012 20:16
Show Gist options
  • Save clly/2370703 to your computer and use it in GitHub Desktop.
Save clly/2370703 to your computer and use it in GitHub Desktop.
Check domain user authentication
$cred = Get-Credential #Read credentials
$username = $cred.username
$password = $cred.GetNetworkCredential().password
$server = "" + ":389"
# Get current domain using logged-on user's credentials
$CurrentDomain = "LDAP://$server" + ([ADSI]"").distinguishedName
$domain = New-Object System.DirectoryServices.DirectoryEntry($CurrentDomain,$UserName,$Password)
if ($domain.name -eq $null)
{
write-host "Authentication failed - please verify your username and password."
exit #terminate the script.
}
else
{
write-host "Successfully authenticated with domain $domain.name"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment