-
Notifications
You must be signed in to change notification settings - Fork 6
rename_workstation_auto_macos.sh
Corey Watson edited this page Dec 1, 2025
·
1 revision
Automatically renames a macOS device using a standardized naming pattern: CLIENT3-USER-UUID.
This script automatically renames a macOS device using a standardized naming pattern. Sets HostName, ComputerName, and LocalHostName. Designed for RMM deployment.
Automatically renames a macOS device using a standardized naming pattern.
Naming Pattern (max 15 chars for NetBIOS compatibility): CLIENT3-USERUUID CLIENT3 : 3-character abbreviation of client name (RMM variable) USER : Sanitized username (maximized, truncated if needed) UUID : Hardware UUID tail (at least 3 chars)
Notes:
- Only A-Z, 0-9, and hyphen used
- Name never starts or ends with '-'
- Always exactly 15 chars
- Sets HostName, ComputerName, and LocalHostName
- Root/sudo access required
- macOS 10.14 or later
- RMM variable $YourClientNameHere must be set
- CLIENT_NAME: RMM variable $YourClientNameHere (3-char abbreviation used)
- MAX_HOST_LEN: Maximum hostname length (default: 15)
- MIN_UUID_LEN: Minimum UUID suffix length (default: 3)
- Gets client name from RMM variable
- Retrieves current logged-in user
- Gets hardware UUID from system
- Builds hostname: CLIENT3-USER-UUID (exactly 15 chars)
- Sets HostName, ComputerName, and LocalHostName
- Flushes DNS cache
- No secrets exposed in output
- Runs with elevated privileges (sudo required)
- 0 - Success
- 1 - Failure (missing inputs, rename failed)
[ INPUT VALIDATION ]
--------------------------------------------------------------
Client Name : ExampleClient
Client Segment (3-char) : EXA
[ SYSTEM VALUES ]
--------------------------------------------------------------
Console User : jsmith
User Segment : JSMITH
Hardware UUID : 12345678-ABCD-EFGH-IJKL-MNOPQRSTUVWX
UUID (clean) : 12345678ABCDEFGHIJKLMNOPQRSTUVWX
Current Hostname : Macintosh
[ BUILD HOSTNAME ]
--------------------------------------------------------------
Prefix : EXA-
User Part : JSMITH
UUID Suffix : TUVWX
Desired Name : EXA-JSMITHTUVWX
Name Length : 15
[ RENAME ACTION ]
--------------------------------------------------------------
Status : RENAMING TO EXA-JSMITHTUVWX
Result : RENAME SUCCESSFUL
Action : Flushing DNS cache
[ FINAL STATUS ]
--------------------------------------------------------------
Hostname set to: EXA-JSMITHTUVWX
HostName, ComputerName, and LocalHostName updated
[ SCRIPT COMPLETED ]
--------------------------------------------------------------
- 1.0.0 (November 2024) - Initial release
- View Script Source
- Scripts - Back to script index