# encoding: ascii # api: powershell # title: Test-ADCredentials # description: Validates a username and password against Active Directory. Requires .NET 3.5 and PowerShell V2. # version: 0.1 # type: function # author: Mike Pfeiffer # license: CC0 # function: Test-ADCredentials # x-poshcode-id: 6267 # x-archived: 2016-10-24T17:03:10 # x-published: 2016-03-24T12:27:00 # # Usage: # Test-ADCredentials username password domain # 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() } }