密码重置脚本错误

密码重置脚本错误

我有以下用于在 AD 中批量重置密码的脚本;

Import-Module ActiveDirectory
$securePwd = ConvertTo-SecureString -String Password -Force -AsPlainText
get-content "C:\Users.txt" |
Foreach {
    if (Get-ADUser -Filter "Name -like '$_'") {Set-ADAccountPassword -NewPassword $securePwd* }
    else {Write-host "Password reset for $_ failed."}
}

从我在线看到的内容来看,这应该可行,但我收到了以下错误;

Set-ADAccountPassword : Cannot bind parameter 'NewPassword'. Cannot convert the "System.Security.SecureString*" value
of type "System.String" to type "System.Security.SecureString".
At C:\Users\Admin\Desktop\ResetPasswords.ps1:5 char:80
+     if (Get-ADUser -Filter "Name -like '$_'") {Set-ADAccountPassword -NewPassword $ ...
+                                                                                   ~
    + CategoryInfo          : InvalidArgument: (:) [Set-ADAccountPassword], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.SetADAccoun
   tPassword

任何帮助是极大的赞赏

答案1

删除使用密码后的 *:

Import-Module ActiveDirectory $securePwd = ConvertTo-SecureString -String Password -Force -AsPlainText get-content "C:\Users.txt" | Foreach {if (Get-ADUser -Filter "Name -like '$_'") {Set-ADAccountPassword -NewPassword $securePwd } else {Write-host "Password reset for $_ failed."} }

相关内容