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

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

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish