【发布时间】: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