0

I have the following script for bulk resetting passwords in 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."}
}

From what i've seen online this should work, but i'm getting the following error;

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

Any help is greatly appreciated

  • Any reason on why you're using the wilcard (*) here: -NewPassword $securePwd* ? – Humberto Castellon Nov 9 '18 at 17:32
  • 3
    I'm pretty sure that * is the source of the problem. – Davidw Nov 9 '18 at 17:39
1

Remove the * after where you use the password:

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."} }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.