Skip to content

rename_workstation_auto_macos.sh

Corey Watson edited this page Dec 1, 2025 · 1 revision

rename_workstation_auto_macos.sh

Automatically renames a macOS device using a standardized naming pattern: CLIENT3-USER-UUID.

Overview

This script automatically renames a macOS device using a standardized naming pattern. Sets HostName, ComputerName, and LocalHostName. Designed for RMM deployment.

Purpose

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

Prerequisites

  • Root/sudo access required
  • macOS 10.14 or later
  • RMM variable $YourClientNameHere must be set

Configuration

Required Inputs

  • 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)

Behavior

  1. Gets client name from RMM variable
  2. Retrieves current logged-in user
  3. Gets hardware UUID from system
  4. Builds hostname: CLIENT3-USER-UUID (exactly 15 chars)
  5. Sets HostName, ComputerName, and LocalHostName
  6. Flushes DNS cache

Security Notes

  • No secrets exposed in output
  • Runs with elevated privileges (sudo required)

Exit Codes

  • 0 - Success
  • 1 - Failure (missing inputs, rename failed)

Example Output

[ 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 ]
--------------------------------------------------------------

Version History

  • 1.0.0 (November 2024) - Initial release

Links

Clone this wiki locally