Skip to content
Menu

Local Admin Password - Rotate It and Store It in a Field

Rotates the password of the built-in Administrator or a named local account to a random 20-character value, written only to a secure RMM field and never printed or logged.

Local admin password - rotate it and store it in a field 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 Local admin password - rotate it and store it in a field. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows 10, Windows 11, Windows Server 2016+; runs as SYSTEM
NeedsPowerShell 5.1, administrator rights, an RMM custom field (secure) to receive the password
Changes thingsChanges what it runs on

What It Does

The script sets a new random 20-character password on one local account. With AccountName empty, the default, it is the built-in Administrator, found by its SID, the local account whose SID ends in -500, even if it was renamed. It may be disabled, and the script does not enable it or change anything except the password. With AccountName set, it is that local account, which must exist. An account that Windows LAPS manages is skipped.

Each successful real run rotates the password, so a second successful run replaces the first password in the field. DryRun previews the rotation without changing the password. The password comes from the operating system's cryptographic random number generator and has upper case, lower case, digits and symbols. It is written to the RMM field before it is set, so a failed field write leaves the account untouched. Afterwards it checks the password change time, and for an enabled account tries one test logon, which security baselines often deny, so a failed test is only a warning.

The password is never printed. It is not in the output, the answer, the data rows, the change log or the exported file. It is written only to the RMM custom field named by ResultField, and NinjaOne, Datto RMM and Syncro are supported. Make that a secure field. Without ResultField, or on an RMM it cannot write to, it refuses before changing anything, and OutputFormat Answer is refused for the same reason.

A domain controller has no local accounts, and the script ends in ERROR there. It does not touch group membership, expiry settings or sessions. Programs, scheduled tasks and services that run as the account with the old password will fail to sign in, so use it on break-glass and built-in accounts, not on accounts something depends on.

Before You Run It

  • Create a secure custom field in your RMM first, and pass its name as ResultField.
  • Check what runs as the account before you rotate it. Services and tasks using the old password will fail.
  • Check who can read that field in your RMM. It holds a working administrator password.
  • Use new-local-admin-account to create a separate break-glass account instead.

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 password on one local user account and writes it to the RMM custom field.
  • Restart: It never restarts the machine.
  • Typical run: Under 15 seconds.
  • Example answer: "Password for local account Administrator rotated; password written to field LocalAdminPassword"
  • Tested before listing on Windows 11 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 local account to rotate. Default empty: the built-in Administrator (SID ending in -500).

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

set-local-admin-password.ps1 · 909 lines · 47 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.