View all Worklets
macOS

Change Hostname to Serial Number

Modifies endpoints hostname to match its serial number.

Worklet Details

Introduction to the Bash-Based Change Hostname to Serial Number Worklet

The Change Hostname to Serial Number Worklet is a bash script designed for MacOS devices that sets the device's hostname to match its serial number. By doing so, it simplifies the management of multiple Mac computers and ensures consistency across different systems. This Worklet is particularly helpful in large organizations and networks, where keeping track of a vast number of devices can be quite challenging.

Why would you use the Change Hostname to Serial Number Worklet?

Organizations often have numerous devices connected to their network, making it difficult for IT administrators to identify each machine uniquely. The Change Hostname to Serial Number Worklet resolves this issue by assigning a unique identifier (the device's serial number) as its hostname.

This allows for seamless management and tracking of Mac computers within an organization while reducing potential errors related to misidentified hardware or duplicate hostnames.

Components of the Change Hostname to Serial Number Worklet

The Worklet consists of two parts: an evaluation code and a remediation code. The evaluation code checks if the current HostName, LocalHostName, and ComputerName match the device's serial number. If they don't match, it will exit with an error status, triggering remediation.

The remediation code then sets these parameters to match the device's serial number using command line utilities like `ioreg`, `scutil`, and `dscacheutil`. Finally, it flushes the DNS cache for immediate effect.

How does the Change Hostname to Serial Number Worklet work?

When executed on a Mac device, this Worklet uses built-in command line utilities such as `ioreg` and `awk` commands to retrieve its serial number information. Then it compares this obtained serial number with existing system parameters (HostName, LocalHostName, and ComputerName).

If there are discrepancies between these values, the remediation part of the Worklet script sets these parameters to match the serial number using `scutil`. Next, the Worklet will flush the DNS cache to ensure that hostname changes take effect immediately without any additional user intervention.

What is the expected outcome when you use the Change Hostname to Serial Number Worklet?

Upon successful execution of this Worklet, all Mac devices in an organization will have their HostName, LocalHostName, and ComputerName set to match their individual serial numbers. This enforces a consistent naming convention for all computers on the network and simplifies device management for IT administrators.

As a result, tracking hardware inventory, scheduling maintenance activities, or troubleshooting issues becomes more efficient as each machine can be precisely identified by its unique serial number-based hostname.

View in app

Consider Worklets your easy button

What's a Worklet?

A Worklet is an automation script, written in Bash or PowerShell, designed for seamless execution on endpoints – at scale – within the Automox platform. Worklet automation scripts perform configuration, remediation, and the installation or removal of applications and settings across Windows, macOS, and Linux.

do more with worklets