如何使用powershell在ActiveDirectory中验证用户身份

and*_*pfr 10 authentication powershell active-directory

我想使用用户名和密码在ActiveDirectory中验证用户.有没有机会使用powershell和activeDirectory模块.谢谢

Cos*_*Key 17

有多种方法可以做到这一点.这是一个快速简单的功能,用于向AD用户进行身份验证.

Function Test-ADAuthentication {
    param($username,$password)
    (new-object directoryservices.directoryentry "",$username,$password).psbase.name -ne $null
}

PS C:\> Test-ADAuthentication "dom\myusername" "mypassword"
True
PS C:\> 
Run Code Online (Sandbox Code Playgroud)

它可能不是满足您需求的最佳功能,但您的问题缺乏细节.


Sha*_*evy 12

需要.NET 3.5和PowerShell V2

$UserName = 'user1'
$Password = 'P@ssw0rd'
$Domain = $env:USERDOMAIN

Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$ct = [System.DirectoryServices.AccountManagement.ContextType]::Domain
$pc = New-Object System.DirectoryServices.AccountManagement.PrincipalContext $ct,$Domain
$pc.ValidateCredentials($UserName,$Password)
Run Code Online (Sandbox Code Playgroud)