How to validate windows domain credentials via the command line?

10,070

There's a very handy PowerShell function here for testing credentials:

Function Test-ADCredentials {
     Param($username, $password, $domain)
     Add-Type -AssemblyName System.DirectoryServices.AccountManagement
     $ct = [System.DirectoryServices.AccountManagement.ContextType]::Domain
     $pc = New-Object System.DirectoryServices.AccountManagement.PrincipalContext($ct, $domain)
     New-Object PSObject -Property @{
          UserName = $username;
          IsValid = $pc.ValidateCredentials($username, $password).ToString()
     }
}

Example use: Test-ADCrendentials -Username joel -Password splotchy -Domain stackoverflow.com

Share:
10,070

Related videos on Youtube

jimmy_terra
Author by

jimmy_terra

Updated on September 18, 2022

Comments

  • jimmy_terra
    jimmy_terra over 1 year

    I want to validate a set of credentials against the domain controller. e.g.:

    Username: STACKOVERFLOW\joel
    Password: splotchy
    

    Can I do this via the command line?

    • Scott Chamberlain
      Scott Chamberlain almost 11 years
      Is the computer you are doing the testing on already a member of the domain?