Last active
November 15, 2018 14:57
-
-
Save huzzeytech/04b1321ee72c26d5779bfccee15a029d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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