对于 Office365,有 1 个登录名和 2 个密码。存储在 $pass1 和 $pass2 变量中。一个有效,另一个无效。 在 PowerShell 中连接到 MS Graph 或 Azure 时,如何在 PowerShell 中快速检查这些密码的真实性?稍后在脚本中使用正确的密码。 我正在考虑在连接到图表时使用密码,但没有连接,但得到响应。成功还是失败。
我找到了一个脚本,但它检查我所在本地域的密码。如何修改脚本来检查 Azure 的密码?
$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"
}