In this article, we will demonstrate how to set macOS device name to serial number using Intune. Instead of renaming macOS devices manually in Intune, you can use a shell script to automatically change the name of Mac devices to its serial number.
Many organisations prefer to use serial numbers as device names as a standard naming convention. A serial number is a unique identifier assigned to a Mac device. If you ever need to use your warranty and have Apple repair your Mac, you’ll need that serial number.
Using Device Naming Templates in Enrollment Profile, you can easily set the serial number as the device name on Windows and iOS/iPadOS devices. However, for macOS devices, you can use a different approach and achieve it with a simple script.
At work, one of the customers recently purchased new MacBooks for their employees. After enrolling them into Intune, they decided to rename all of their devices to their serial number. Normally, a macOS device name is a combination of the full name of the first account and the model of mac. For example, my test Mac has the device name Prajwal’s MacBook.
In the Intune portal, you can rename a corporate macOS device using the “Rename” option that is located under the device properties. However, this method is feasible when you have a handful of macOS devices. If you want to bulk rename macOS device names to their serial numbers, you must use the DeviceRename.sh script.
Before you set MacOS device name to serial number using Intune, the following prerequisites are required.
- The macOS devices must be running version 11.0 or later.
- You must enroll macOS devices in Intune before you run shell scripts.
- The macOS devices must be connected directly to the Internet. Connection through a proxy is not supported.
- You must have a script ready to apply it to macOS devices.
- Shell scripts begin with #! and must be in a valid location such as #!/bin/sh or #!/usr/bin/env zsh. For more details, read how to use shell scripts on macOS using Intune.
Interesting Read: Install Google Chrome on macOS using Intune
Download the Script to Change macOS Device Name to Serial Number
To change macOS device name to serial number on macOS using Intune, you’ll require the shell script. You can download the DeviceRename.sh script file from the Prajwal Desai GitHub repository. The script will run on a macOS device and sets the device name to the matching serial number.
Note: The device rename script for macOS is also available on Microsoft Intune Scripts GitHub repository. However, the link shared above contains the modified version of the script that renames device name to serial number instead of the modelcode-serialnumber-country. More about this is explained in the next section.
macOS DeviceRename.sh Script Modification
The shell script provided by Microsoft to rename macOS device assigns the device name in the following format.
If you use the device rename script by Microsoft, it will detect the Mac Model, the serial number and the country, using the current public IP address, and sets the device name as “Model Name”-“Serial Number”-“Country”.
To make it simple, you can edit the DeviceRename.sh script and use the below code to set macOS device name to serial number. If you are downloading the script from the Prajwal Desai GitHub repository, the below modification is already done for you.
Also Read: Deploy MacOS DMG apps with Intune
Set MacOS Device Name to Serial Number using Intune
Let’s go through the steps to upload the DeviceRename.sh script to Intune, which will change the device name to serial number for macOS devices.
- Sign in to Microsoft Intune Admin Center.
- Navigate to Devices > macOS and select Shell Scripts.
- Click the Add button to upload the DeviceRename.sh script for macOS.
Enter a name for the profile in the Basics tab of the Add Script pane. Add a brief description about the policy.
For instance, you can enter the following information for macOS Shell script:
- Name: Change MacOS Device name to Serial Number
- Description: Rename the Mac Devices to its Serial Number
On the Script Settings tab, upload the macOS script. Click on the Browse icon and select the DeviceRename.sh script. Keep in mind that the macOS shell script file must be less than 200 KB in size. You can view the script that has been uploaded, but you cannot edit or modify the script at this time.
Scroll down to configure the following script settings in the same window.
- Run script as signed-in user: No
- Hide script notifications on devices: Not configured
- Script frequency: Every 1 week
- Number of times to retry if script fails: 3
On the Assignments tab, you select the Azure groups to assign the macOS device rename shell script. The groups you select are shown in the list, and will receive your script policy. Click Next.
In Review + add, a summary is shown of the settings you configured. Select Add to save the script. When you select Add, the script policy is deployed to the macOS device/user groups you chose.
You’ll see a notification “Upload completed for DeviceRename.sh” confirming that the script has been uploaded successfully to Intune.
The macOS device rename shell script you created now appears in the list of scripts. If needed, you can select and view the contents of macOS shell scripts after you upload them to Intune. You must wait for the shell script policy to apply to the targeted groups, and once the devices check-in with the Intune service, they will receive the script. You can also run Check Status in company portal on your Mac device to retrieve the latest policies from Intune.
Also Read: Set Desktop Wallpaper for Mac using Intune
Monitor the Device Name Change in Intune
Now it’s time to monitor if the script is assigned to the macOS devices and verify if the devices have been renamed to their serial numbers.
You can monitor the run status of all assigned macOS scripts for users and devices by choosing one of the following reports in Intune:
- Shell Scripts > select the script to monitor > Device status.
- Shell Scripts > select the script to monitor > User status.
From the screenshot below, we see the macOS device rename script succeeded on our mac devices. This confirms that the DeviceRename.sh script works correctly on Mac devices and if you follow the steps in order, you can achieve the same results.
Go to Monitor > Device Status, and here you will find the macOS devices on which device name is changed to its serial number. We see that the macOS device name is now replaced with its serial name and status shows as succeeded.
In the Intune admin portal, navigate to Devices > macOS. Here you will find a list of macOS devices and the device name now shows as serial number.
When the user launches the company portal on Mac, the device name is now changed to its serial number.
Changing MacOS device name to Serial Number using Intune can be achieved with a script. Although not all organisations prefer to use serial numbers as naming conventions for Mac devices, this is a better naming strategy for Mac devices. You can also use model code along with the serial number as device names to identify macOS managed devices in Intune.