Verify Active Directory credentials

Verify Active Directory credentials

This function takes a user name and a password as input and will verify if the combination is correct. The function returns a boolean based on the result.

The samaccountname of the Active Directory user account

The password of the Active Directory user account

Check-ADCredential -username khaleeso -password SuperFakePassword

Verifies if the username and password provided are correct, returning either true or false based on the result

function Check-ADCredential {
if (!($UserName) -or !($Password)) {
Write-Warning 'Check-ADCredential: Please specify both user name and password'
} else {
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('domain')
$DS.ValidateCredentials($UserName, $Password)

Leave a comment

Your email address will not be published. Required fields are marked *