PoshCode Archive  Artifact Content

Artifact 7a6731b3910932da64755449d14d8080c74c2b9180662251b386377eab4c4280:

  • File Test-ADCredentials.ps1 — part of check-in [95f856b518] at 2018-06-10 12:56:59 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: 1393
# x-archived: 2017-04-11T01:02:21
# x-published: 2010-10-13T23:29: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()
	}
}