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
(6)
11,926 times
Add to favorites
Active Directory
5/10/2013
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • 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: https://gist.github.com/JohnLBevan/69b38d42466e5612e22c2c651daf52c0