我正在尝试使用PowerShell脚本重置密码。我在执行脚本时遇到以下错误

时间:2016-10-19 09:55:55

标签: powershell scripting active-directory change-password

+ CategoryInfo          : InvalidData: (TA-SRV-INB**-****-*:ADAccount) [Set-ADAccountPassword], ADInvalidPasswordException
+ FullyQualifiedErrorId : The specified network password is not correct,Microsoft.ActiveDirectory.Management.Commands.SetADAccountPassword

我在执行PowerShell脚本以重置其中一个帐户的密码时遇到上述错误。

1 个答案:

答案 0 :(得分:0)

首先验证旧密码。并确保您的新密码符合密码复杂性要求。

$AccountName='Account Name'
$OldPassword ='Old Password'
$NewPassword='New Password'

# Verifying password
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('domain')
$Validate = $DS.ValidateCredentials($AccountName, $Password)

#Password Change

Set-ADAccountPassword -Identity "$AccountName" -OldPassword (ConvertTo-SecureString -AsPlainText $OldPassword -Force) -NewPassword (ConvertTo-SecureString -AsPlainText $NewPassword -Force)

希望这个HElps。