PoshCode Archive  Artifact Content

Artifact d6650980649850f0536fa93f4f4e1289a861f05ff417e55850d34a4b6675ecf2:

  • File Test-ADCredentials.ps1 — part of check-in [d4ce3fa56d] at 2018-06-10 13:51:44 on branch trunk — Validates a username and password against Active Directory. Requires .NET 3.5 and PowerShell V2. (user: Mike Pfeiffer size: 885)

# 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: 5194
# x-archived: 2016-05-07T09:53:48
# x-published: 2016-05-27T13:16: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()
	}
}