domain – 检查用户密码输入在Powershell脚本中是否有效

我正在使用Power shell脚本,该脚本将计划任务添加到我们域中的系统.当我运行此脚本时,它会提示我输入密码.我有时会忘记密码并开始流程,这会锁定我的帐户.有没有办法验证我的凭据,以确保我输入的内容将使用域验证?

我想找到一种查询域控制器的方法.我已经完成了一些谷歌搜索,我应该能够进行WMI查询并捕获错误.如果可能的话,我想避免这种验证方式.

有任何想法吗?提前致谢.

解决方法

我在我的图书馆里有这个:
$cred = Get-Credential #Read credentials
 $username = $cred.username
 $password = $cred.GetNetworkCredential().password

 # Get current domain using logged-on user's credentials
 $CurrentDomain = "LDAP://" + ([ADSI]"").distinguishedname
 $domain = New-Object System.DirectoryServices.DirectoryEntry($CurrentDomain,$UserName,$Password)

if ($domain.name -eq $null)
{
 write-host "Authentication Failed - please verify your username and password."
 exit #terminate the script.
}
else
{
 write-host "Successfully authenticated with domain $domain.name"
}

相关文章

vue阻止冒泡事件 阻止点击事件的执行 <div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些