Library / Windows endpoint

WIN-024 · Script

Rename Computer from Naming Standard

Builds a computer name from your naming pattern (prefix, serial number, site, type, asset tag) and, in Apply mode, renames the device.

Version 1.0.0Language PowerShellUpdated November 2026

What it does

The new name is built from -Pattern by replacing these tokens: {PREFIX} the -Prefix value

  • {SITE}: the -Site value
  • {TYPE}: the -DeviceType value, or detected: L = laptop/tablet, D = desktop, V = virtual machine

{SERIAL} the BIOS serial number (Win32_BIOS), optionally only the last -SerialLength characters

  • {ASSET}: the -AssetTag value, or the asset tag stored in the firmware (Win32_SystemEnclosure)

Every token is cleaned to letters, digits and hyphens and upper-cased.

The result is checked against the NetBIOS rules: at most 15 characters, only A-Z, 0-9 and hyphen, not only digits, and no leading or trailing hyphen. Placeholder serials such as "To be filled by O.E.M." or "Default string" are rejected. If the name breaks a rule, nothing is changed and the script exits 1.

Report mode (default) logs the current and the proposed name only. Apply mode renames the device with Rename-Computer. The new name takes effect after the next restart; the device is not restarted unless -Restart is used.

Supported: workgroup and Microsoft Entra joined devices. Renaming an on-premises domain-joined device needs domain credentials, so for domain-joined devices the script logs a warning and makes no change. Runs silently as SYSTEM from any RMM or Intune. No prompts, no user interaction.

Requirements

Windows PowerShell 5.1+, run as SYSTEM or local admin. Workgroup or Microsoft Entra joined device.

How to run it

  • Run as: SYSTEM or a local administrator
  • Run from: any RMM or MDM, Intune, a Group Policy startup script, a scheduled task, or an elevated PowerShell window
  • Script type: PowerShell, 64-bit
  • User interaction: none; the script never prompts
  • Timeout: 10 minutes (30 for Windows Update installs)

Settings

NameWhat it doesOptionsDefault
ModeReport (default) = read-only. Apply = rename the device.Report, ApplyReport
PatternNaming pattern with tokens. Default {PREFIX}-{SERIAL}. Examples: {SITE}-{TYPE}-{SERIAL}, {PREFIX}{ASSET}, LAB-{SERIAL}.{PREFIX}-{SERIAL}
PrefixText for the {PREFIX} token, for example ACME or HS.
SiteText for the {SITE} token, for example NYC or ELM.
DeviceTypeText for the {TYPE} token. If empty it is detected (L, D or V). Example: STU for student devices.
AssetTagText for the {ASSET} token. If empty, the asset tag stored in the firmware is used.
SerialLengthUse only the last N characters of the serial number. 0 (default) = the full serial. Example: 7.0
RestartRestart the device right after the rename so the new name takes effect. Off by default.False

Exit codes

  • 0 = Name already correct, or rename done (restart pending unless -Restart)
  • 1 = Rename needed (Report), name breaks a rule, bad serial, or domain-joined device
  • 2 = Script error

Testing steps

  1. Run it first with the mode set to Report on one test device. Nothing is changed in that mode.
  2. Read the log and confirm the planned changes are what you expect.
  3. Run your chosen settings on the same test target and confirm the result.
  4. Check the exit code: 0 = OK, 1 = needs attention, 2 = error (see log), 9 = this copy is past its Valid until date.
  5. Roll out to a small group next, then everyone.

Rollback steps

Run the script again with a pattern that produces the old name, or run Rename-Computer -NewName <old name> -Force as admin, then restart. The old name is in the log line 'Current name: ...'.

Version and change log

VersionDateChanges
1.0.0November 2026First release.