Ricky

链接

RSS

RSS Link
SSH登录Windows的Linux子系统
修改DLL

测试AD用户密码

Ricky posted @ 2016年11月24日 12:37 in Other , 304 阅读
<#
.Synopsis
Verify Active Directory credentials
 
.DESCRIPTION
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.
 
.NOTES   
Name: Test-ADCredential
Author: Jaap Brasser
Version: 1.0
DateUpdated: 2013-05-10
 
.PARAMETER UserName
The samaccountname of the Active Directory user account
 
.PARAMETER Password
The password of the Active Directory user account
 
.EXAMPLE
Test-ADCredential -username jaapbrasser -password Secret01
 
Description:
Verifies if the username and password provided are correct, returning either true or false based on the result
#>
function Test-ADCredential {
    [CmdletBinding()]
    Param
    (
        [string]$UserName,
        [string]$Password
    )
    if (!($UserName) -or !($Password)) {
        Write-Warning 'Test-ADCredential: Please specify both user name and password'
    } else {
        Add-Type -AssemblyName System.DirectoryServices.AccountManagement
        $DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('domain')
        $DS.ValidateCredentials($UserName, $Password)
    }
}
Test-ADCredential "username" "defaultpass"

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter