Library / macOS

MAC-002 · Script

Computer Rename

Sets the Mac's ComputerName, HostName, LocalHostName and SMB NetBIOS name to one clean, standard name built from the serial number or a name you supply. Safe to run again; it only changes names that do not already match.

Version 1.0.0Language bashUpdated November 2026

What it does

Sets the Mac's ComputerName, HostName, LocalHostName and SMB NetBIOS name to one clean, standard name built from the serial number or a name you supply. Safe to run again; it only changes names that do not already match.

Requirements

macOS 12 or later, run as root (MDM or RMM default). No prompts.

How to run it

  • Run as: root (sudo in Terminal, or your MDM default)
  • Run from: any MDM or RMM, a LaunchDaemon, or Terminal with sudo
  • Script type: shell script (bash)
  • User interaction: none; the script never prompts
  • Timeout: 10 minutes (longer for app or update installs)

Settings

NameWhat it doesOptionsDefault
modedefault reportreport, applyreport
sourcedefault serialserial, nameserial
namerequired when --source=name
prefixoptional, for example LIB-
suffixoptional
max-lengthdefault 15, the NetBIOS limit15

Exit codes

  • 0 = Names already match, or were set
  • 1 = Names differ (report mode)
  • 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

Report mode changes nothing. The log records the old names. Run again with --source=name and the old name.

Version and change log

VersionDateChanges
1.0.0November 2026First release.