Skip to content

Instantly share code, notes, and snippets.

@rafalf
Last active August 28, 2016 15:14
Show Gist options
  • Save rafalf/ed2c2cdbf5e9af70e059 to your computer and use it in GitHub Desktop.
Save rafalf/ed2c2cdbf5e9af70e059 to your computer and use it in GitHub Desktop.
Test windows user credentials
#
# Returns True if Password matches, False otherwise
#
Function Test-UserCredential {
Param($username, $password)
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$ct = [System.DirectoryServices.AccountManagement.ContextType]::Machine, $env:computername
$opt = [System.DirectoryServices.AccountManagement.ContextOptions]::SimpleBind
$pc = New-Object System.DirectoryServices.AccountManagement.PrincipalContext -ArgumentList $ct
$Result = $pc.ValidateCredentials($username, $password).ToString()
$Result
}
Test-UserCredential -username SvcAc_Workflows -password Password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment