How can I change the password of many users with PowerShell in AD

Easily reset passwords of many AD users with PowerShell

John Savill

March 12, 2017

1 Min Read
How can I change the password of many users with PowerShell in AD

Q. How can I easily change the password of many users?

A. The script below can be used to change the password and unlock the account of every user based on their SAMAccountName but could be changed based on user objects directly easily.

$securePassword = ConvertTo-SecureString "Pa55word!123" -AsPlainText -Force

foreach($samname in $samlist)
{
  $userobj = Get-ADUser -LDAPFilter "(SAMAccountName=$samname)"
  if ($userobj -ne $null)
  {
    $userobj | Set-Aduser -ChangePasswordAtLogon $false
    $userobj | Set-ADAccountPassword -NewPassword $securePassword -Reset
    $userobj | Unlock-ADAccount
  }
}

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like