Last active
January 12, 2018 15:39
-
-
Save VimalShekar/fd1429a154f8b6843cfe6439cabfc541 to your computer and use it in GitHub Desktop.
Checking if given username and password is valid in PowerShell
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
# -- Get the full script here : https://github.com/VimalShekar/PowerShell/blob/master/CheckIsUserValid_1.ps1 | |
function IsLocalUserNamePasswordValid() | |
{ | |
param( | |
[String]$UserName, | |
[String]$Password | |
) | |
$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('machine',$ComputerName) | |
$bReturn = $DS.ValidateCredentials($UserName, $Password) | |
return $bReturn | |
} | |
function IsDomainUserNamePasswordValid() | |
{ | |
param( | |
[String]$UserName, | |
[String]$Password, | |
[String]$DomainName | |
) | |
$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('domain',$DomainName) | |
$bReturn = $DS.ValidateCredentials($UserName, $Password) | |
return $bReturn | |
} | |
#Example Usage: | |
#IsLocalUserNamePasswordValid -UserName TestLocalUser1 -Password Test@Pass1 | |
#IsDomainUserNamePasswordValid -UserName TestDomUser1 -Password Test@Pass1 -DomainName testdom.local |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment