Created
November 6, 2017 15:29
-
-
Save kpatnayakuni/fc0f7f8da7a995ec18db33666843064e to your computer and use it in GitHub Desktop.
Validates domain credentials
This file contains 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
function Test-ADCredential | |
{ | |
$Credentials = Get-Credential -Message 'Enter your domain credentials' | |
$UserName = $Credentials.UserName | |
$Password = $Credentials.GetNetworkCredential().Password | |
Add-Type -AssemblyName System.DirectoryServices.AccountManagement | |
$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('domain') | |
try | |
{ | |
$Status = $DS.ValidateCredentials($UserName, $Password) | |
if ($Status) { Write-Host -ForegroundColor Green "Credentials authenticated successfully!" } | |
else { Write-Host -ForegroundColor Red "Credentials authentication failed!" } | |
} | |
catch { Write-Host -ForegroundColor Red "Credentials authentication failed!" } | |
} | |
Test-ADCredential |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment