Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $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
- }
Add Comment
Please, Sign In to add comment