Skip to content
Menu

Reset an AD User's Password - Random, Forced Change at Logon

Sets a random 20-character password on one AD user and writes it only to a secure RMM field. By default it requires a change at next sign-in and unlocks the account if locked.

Reset an AD user's password - random, forced change at logon is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Reset an AD user's password - random, forced change at logon. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows Server 2016+ (domain controller or domain member); runs as SYSTEM
NeedsPowerShell 5.1; admin rights; ActiveDirectory module; rights to reset passwords; a secure RMM field
Changes thingsChanges what it runs on

What It Does

For the one user in AccountName (sign-in name, DOMAIN\name or user principal name) the script sets a new random 20-character password with upper and lower case letters, digits and symbols. With ChangePasswordAtLogon true, the default, the user must choose a new password at next sign-in. With UnlockAccount true, the default, a locked-out account is unlocked. It resets domain accounts only; for a local account use set-local-admin-password.

The password is never printed. It is not in the output, the answer, the data rows, the change log or an exported file. It is written only to the RMM custom field named by ResultField, and it is written before it is set, so a failed field write changes nothing. Without ResultField, or on an RMM it cannot write to, the script refuses before changing anything, and OutputFormat Answer is refused for the same reason.

It refuses the built-in accounts (RIDs 500 to 503, including krbtgt) and anything marked as a critical system object, and a user that is not found. A password-never-expires account cannot be forced to change at next sign-in, because Active Directory refuses it: the script stops and tells you to set ChangePasswordAtLogon to false. A disabled account gets the new password and stays disabled; the script never enables it.

When ChangePasswordAtLogon is true and Active Directory already requires a password change at next sign-in, the script leaves the password as it is unless ForceReset=true. It can still unlock the account if requested. It does not check whether the secure field contains the current password. With ChangePasswordAtLogon=false, each run issues a new password. DryRun lists the planned changes.

Before You Run It

  • Run it on a domain controller or a member server with the ActiveDirectory module (RSAT) and administrator rights.
  • Create a secure custom field in your RMM first and pass its name as ResultField. Check who can read it.
  • Run it with DryRun=true first to see the account's state and the steps it would take.
  • For a service account with a password that never expires, set ChangePasswordAtLogon to false, and check what uses the old password.

Type and Risk

  • Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
  • Risk: Low. Set DryRun=true, or run it with -WhatIf, to list every change without making any.
  • What it changes: Sets a new random password on one AD user, can require a change at next sign-in and unlock the account, and writes the password to the RMM custom field.
  • Restart: It never restarts the machine.
  • Typical run: Under 15 seconds.
  • Example answer: "Password for jsmith reset; must change at next sign-in; password written to field UserPassword"
  • Tested before listing on a Windows Server 2025 domain controller (VM) with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.

Inputs

Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.

  • AccountName: The user: the sign-in name (jsmith), DOMAIN\jsmith, or the user principal name. Required. (Named AccountName, not UserName: Windows already has an environment variable called USERNAME.)
  • ChangePasswordAtLogon: true to make the user change the password at next sign-in. Default true.
  • UnlockAccount: true to also unlock a locked-out account. Default true.
  • ForceReset: true to issue a new password even when the user already must change it at next sign-in. Default false.

Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

reset-ad-user-password.ps1 · 916 lines · 47.6 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.