Skip to content

Commit 0ef870f

Browse files
Create Test-ADCredential.ps1
1 parent 9b88b26 commit 0ef870f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<#
2+
.Synopsis
3+
Verify Active Directory credentials
4+
.DESCRIPTION
5+
This 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.
6+
.NOTES
7+
Name: Test-ADCredential
8+
Version: 1.0
9+
.PARAMETER UserName
10+
The samaccountname of the Active Directory user account
11+
.PARAMETER Password
12+
The password of the Active Directory user account
13+
.EXAMPLE
14+
Test-ADCredential -username username1 -password Password1!
15+
Description:
16+
Verifies if the username and password provided are correct, returning either true or false based on the result
17+
#>
18+
function Test-ADCredential {
19+
[CmdletBinding()]
20+
Param
21+
(
22+
[string]$UserName,
23+
[string]$Password
24+
)
25+
if (!($UserName) -or !($Password)) {
26+
Write-Warning 'Test-ADCredential: Please specify both user name and password'
27+
} else {
28+
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
29+
$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('domain')
30+
$DS.ValidateCredentials($UserName, $Password)
31+
}
32+
}

0 commit comments

Comments
 (0)