Verify the Active Directory credentials of a user account

This PowerShell 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.

4.8 Star
14,252 times
Add to favorites
Active Directory
E-mail Twitter Digg Facebook
  • Exception calling "ValidateCredentials" with "2" argument(s): "Access is denied.
    1 Posts | Last post October 18, 2019
    • Hello,
      I get access denied. I can login with those creds manually but not using this POwerShell script
  • Small sugestion
    3 Posts | Last post April 20, 2018
    • Hello,
      The script works great, small and simple!
      I'd just like it to not have the passwords passed as clear text. I looked around and found that I can pass the credentials to a variable with the Get-Credential and then inside the script manipulate with something like $variable.UserName and $variable.GetNetworkCredential().Password.
      Your opinion? :)
    • Hi,
      $Usr = Read-Host 'username?'
      $Pas = Read-Host  'password?' -assecurestring 
      Test-ADCredential -username $Usr -password ([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Pas)))
      Pls try again.
    • Tweaked version here: