Verify the Local User account credentials

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. A computername can be specified to check account details on remote systems.

 
 
 
 
 
5 Star
(3)
8,026 times
Add to favorites
Active Directory
5/20/2013
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Does this require admin privileges?
    1 Posts | Last post September 05, 2018
    • Hi,
         I tried the script and noticed that it will not work on systems that I do not have admin privileges. I was testing the Administrator user.
      
      Is this expected?
      
  • Windows 10
    1 Posts | Last post December 19, 2017
    • Hi Jaap!
      Is this script supposed to make a remote call to the supplied computername for a local account?
      Im using Win10 1703 and its giving me a "Exception calling "ValidateCredentials" with "2" argument(s): "Logon failure: the user has not been granted the requested logon type at this computer."
      Does the script need an Invoke-Command to run local on the remote computer?
  • hi Jaap i tried this on Windows 10 doesnt seem to work. Does this require any modification to work on Windows 10?
    2 Posts | Last post April 07, 2017
    • hi Jaap i tried this on Windows 10 doesnt seem to work. Does this require any modification to work on Windows 10?
    • It should work on Windows 10, I just re-verified this with the latest build. Which version of Windows 10 are you on, you can check this by running winver.exe to show the Windows version information.
      
      
      Regards,
      
      Jaap Brasser
  • I am getting wrong report.
    2 Posts | Last post April 07, 2017
    • Hello Jaap,
      
      I am getting test credential result as false, However I am using correct combination of user Name and Password. I tested with my domain credentials and It showed true.
      
      Please help me in understanding where could be this issue.
    • How are you running this exactly?
      
      Can you try running the following and let me know if this works:
      net user testuser testpass /add
      Test-LocalCredential -UserName testuser -Password testpass
  • Testing Credentials for Multiple computer
    5 Posts | Last post October 07, 2016
    • Hi Jaap,
      
      This script works like a charm thanks.
      Just had a few questions. Can I test the credentials of multiple system? 
      Ex: like I have file example.txt which has all the system on which I have to test the credentials Can I add this file as a variable to the script? and if possible can I get the result into the other file like result.txt.
      
      Any help will be appreciated much. Thank again.
    • Sure that is possible, here is an example of doing this against a number of systems in a plain text file to verify the credentials of Jaap Brasser. The code is as follows:
      
      . .\Test-LocalCredential.ps1
      Get-Content YourComputerNames.txt | ForEach-Object {
          Write-Output ('Testing computer: {0}' -f $_)
          Test-LocalCredential -UserName jaapbrasser -Password Secret01 -ComputerName
      }
      
      
      Let me know if that helps.
      
      
      Regards,
      
      Jaap Brasser
    • Sorry the code was incorrectly copied, this is the code you need to execute:
      
      . .\Test-LocalCredential.ps1
      Get-Content YourComputerNames.txt | ForEach-Object {
          Write-Output ('Testing computer: {0}' -f $_)
          Test-LocalCredential -UserName jaapbrasser -Password Secret01 -ComputerName $_
      }
    • Thanks Jaap, It's working as expected thank a ton again :).
      
    • Glad to hear that, happy to help!
      
      
      Regards,
      
      Jaap Brasser
  • Test Credentials on different computers
    3 Posts | Last post June 02, 2016
    • Sorry me again. Could it be then possible to check the credentials on the different Computers, and after the check put the result for example in a TXT-File?
      Example:
      Computer 1 True
      Computer 2 False
      ....
      Best regards
    • No this is currently not possible, you could script around this using existing cmdlets though. Could you give an example of what kind of input file you would like to use?
    • Hi coccone,
      It is possible but it will appears one above the other.
      
      Example:
      Computer1
      True
      Computer2
      False
      ... 
      
      You only have to "print" before the validation part, the computer name
      
      Original code:
      
      Add-Type -AssemblyName System.DirectoryServices.AccountManagement
              $obj = New-Object     System.DirectoryServices.AccountManagement.PrincipalContext('machine',$computer)
              $obj.ValidateCredentials($username, $password)   
      
      Edited
      
      Add-Type -AssemblyName System.DirectoryServices.AccountManagement
              $obj = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('machine',$computer)
              Write-Host $computer #just add this line and it will show you first the computer name and then the true or false result.
              $obj.ValidateCredentials($username, $password)   
  • Test Credentials on different computers
    1 Posts | Last post December 27, 2013
    • Hello could it be possible to expand the script, that we could define more than just 1 Computer, where we could check the credentials?
      Best regards