【问题标题】:Unpredictable output when setting user account passwords设置用户帐户密码时出现不可预测的输出
【发布时间】:2018-06-07 20:28:28
【问题描述】:

我有以下代码,顶部有一些设置,代码是从下面的循环体中提取的:

Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$DIR_SVCS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('domain')

## Other stuff...

## usersOU is set to the domain of the users (...,OU=users,dc=<domain>...)
Search-ADAccount -LockedOut -SearchBase $usersOU | Unlock-ADAccount

## Loop code...
$userID = 'myuser'
$password = 'TempPa$$w0rd'
$SecurePW = ConvertTo-SecureString ($password) -AsPlainText -Force

Set-ADAccountPassword $userID -Reset -NewPassword $SecurePW | Out-Null
if ((-Not $?) -or ($LASTEXITCODE -gt 0)) {
    Throw "ERROR with Set-ADAccountPassword exit code $LASTEXITCODE on $userID"
}

if ($DIR_SVCS.ValidateCredentials($userID, $password)) {
    Write-Host "Validated new account password: $userID"
} else {
    Write-Host "FAILED validation of new account password: $userID"
}

这是在一组用户和密码中执行的,输出让我摸不着头脑:

Validated new account password: user1
FAILED validation of new account password: user2
FAILED validation of new account password: user3
Validated new account password: user4
FAILED validation of new account password: user5
...

我看不出为什么这在某些方面会失败而在其他方面会成功。所有被修改的用户都存在于上面解锁的“$usersOU”中,但我希望在“Set-ADAccountPassword”调用之后会抛出一个错误,或者所有验证调用都会成功......

任何理解这里发生的事情的帮助将不胜感激!

【问题讨论】:

  • 您的环境中是否有多个 DC?
  • @EBGreen 是的,我执行的故障排除步骤之一是确保两个 DC 同步..
  • 您的意思是在设置密码和验证凭据之间?一旦您在帐户上设置密码,一个 DC 就会与另一个不同,直到复制发生。
  • 您应该指定 -Server 并使用 PDC 模拟器。

标签: powershell active-directory passwords user-accounts


【解决方案1】:

这通常在多域控制器环境中从 ActiveDirectory 模块和 .NET 查询活动目录时看到。这可以通过确保两者都与同一台服务器通信来缓解,最简单的方法可能是将 $DIR_SVCS 中的“ConnectedServer”属性与 Search-ADAccount 一起使用

举个例子:

Search-ADAccount -LockedOut -SearchBase $usersOU -Server $DIR_SVCS.ConnectedServer | Unlock-ADAccount

【讨论】:

    猜你喜欢
    • 2014-01-07
    • 2022-11-04
    • 1970-01-01
    • 1970-01-01
    • 2020-07-15
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 1970-01-01
    相关资源
    最近更新 更多