如何使用 powershell 对 ActiveDirectory 中的用户进行身份验证

发布于 2024-12-08 11:16:52 字数 96 浏览 0 评论 0原文

我想使用用户名和密码对 ActiveDirectory 中的用户进行身份验证。是否有机会使用 powershell 和 activeDirectory 模块来做到这一点。 谢谢

I would like to authenticate an user in my ActiveDirectory with the Username and the Password. Is there any chance to do that with powershell and the activeDirectory module.
Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

随波逐流 2024-12-15 11:16:52

有多种方法可以做到这一点。这是一个快速简单的函数,用于向 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:\> 

它可能不是最适合您需求的功能,但您的问题缺乏细节。

There are multiple ways of doing this. Here is a quick and simple function which authenticates a user to 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:\> 

It might not be the best function for your needs but your question lacks details.

迷鸟归林 2024-12-15 11:16:52

需要 .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)

Requires .NET 3.5 and 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)
难理解 2024-12-15 11:16:52

这是我的脚本版本。
在此版本中,凭据不是以纯文本形式存储的,
当您运行该函数时,它会提示您输入凭据和

Function Test-ADAuthentication {
$Cred = 获取凭证
(新对象 DirectoryServices.DirectoryEntry "",$($Cred.UserName),$($cred.GetNetworkCredential().password)).psbase.name -ne $null
如果

传递错误返回 false,如果传递正确返回 true

here is my version of the script.
In this vesion the credentials are not stored in plain text,
when you run the function it will prompt you to enter the credentials and

Function Test-ADAuthentication {
$Cred = Get-Credential
(New-Object DirectoryServices.DirectoryEntry "",$($Cred.UserName),$($cred.GetNetworkCredential().password)).psbase.name -ne $null
}

If pass is wrong return false, if pass is right return true

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文