Skip to content

Instantly share code, notes, and snippets.

@artschwagerb
Created July 15, 2015 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artschwagerb/7636463a718339b67768 to your computer and use it in GitHub Desktop.
Save artschwagerb/7636463a718339b67768 to your computer and use it in GitHub Desktop.
Check AD Username/Password
$cred = Get-Credential #Read credentials
$username = $cred.username
$password = $cred.GetNetworkCredential().password
# Get current domain using logged-on user's credentials
$CurrentDomain = "LDAP://hillsborough.k12.nj.us"
$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."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment