Skip to content

Instantly share code, notes, and snippets.

@huzzeytech
Last active November 15, 2018 14:57
Show Gist options
  • Save huzzeytech/04b1321ee72c26d5779bfccee15a029d to your computer and use it in GitHub Desktop.
Save huzzeytech/04b1321ee72c26d5779bfccee15a029d to your computer and use it in GitHub Desktop.
$userName = $args[0]
$password = $args[1]
$hostName = $args[2]
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
Function Validate-Credentials{
$principalContext = New-Object System.DirectoryServices.AccountManagement.PrincipalContext("Machine","$hostname")
$validate=$principalContext.ValidateCredentials($userName, $passWord)
if($validate) {
return $true
}
elseif($validate -eq $false) {
throw "Bad username or Password"
}
else {
throw $_.Exception.InnerException
}
}
try {
Validate-Credentials
}
catch {
throw $_.Exception.InnerException
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment