What It Does
The script sets the computer name and nothing else. It does not restart the PC, or change the domain, the DNS suffix, the RMM agent or any user. The new name takes effect at the next restart, and until then Windows keeps the old name and the pending name is stored. The answer says a restart is needed.
Give the name one of two ways. NewName is for one device, because a NewName set site-wide in an RMM would try to give every PC the same name. Use Pattern for a fleet: a name built from tokens, for example {PREFIX}-{SERIAL}. {PREFIX} is the Prefix input. {SERIAL} is the BIOS serial number with everything except letters and digits removed, in capitals. When the name would be longer than 15 characters, the serial is shortened from the front, so its last characters are kept, and the rest of the pattern is never cut. A serial that is empty or a maker's placeholder is refused when the pattern uses it. Different serials can still produce the same name after cleaning or shortening.
A computer name must be 1 to 15 characters of letters, digits and hyphens, not starting or ending with a hyphen and not only digits. When the rename is already queued, or the PC has the wanted name with no other rename queued, it changes nothing and says so. If the PC has the wanted name but another rename is queued, it cancels that queued rename.
It is SKIPPED on a PC joined to an Active Directory domain, because renaming a domain computer needs domain credentials. Windows Server is skipped unless AllowServers is true. That setting does not override the domain-join check.
Before You Run It
- Use NewName on one PC only. Use Pattern for a fleet.
- Use DryRun=true to see the proposed name. Check for duplicates before applying a pattern across the fleet.
- Plan the restart that finishes the rename. The script never restarts the PC.
- Rename domain-joined PCs from Active Directory, or unjoin them first.
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: Computer name (takes effect at the next restart).
- Restart: A restart is needed to finish. It never restarts the machine itself, and the answer says so.
- Typical run: Under 10 seconds.
- Example answer: "Renamed DESKTOP-4F2K9 to ACME-7XK2QY3; restart needed to finish"
- 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.
- NewName: The exact new computer name. Do not combine with Pattern.
- Pattern: A name pattern with the tokens {PREFIX} and {SERIAL}, for example {PREFIX}-{SERIAL}. Do not combine with NewName. Other text in the pattern must be letters, digits or hyphens.
- Prefix: Text for the {PREFIX} token: letters, digits and hyphens, up to 14 characters. Required when the Pattern uses {PREFIX}.
- AllowServers: Windows Server and domain controllers are skipped unless this is true, because renaming a server breaks what depends on its name. true or false. 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.