Last active
August 28, 2016 15:14
-
-
Save rafalf/ed2c2cdbf5e9af70e059 to your computer and use it in GitHub Desktop.
Test windows user 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
# | |
# 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