Set Device Name to Serial Number for macOS Intune managed devices

Recently at work, we started to introduce some new Apple macOS devices.  As part of enhancing the employee experience, I decided to incorporate Apple Business Manager to help with onboarding macOS devices along with improving management of these devices with Intune.

I’m planning to blog a bit on some of the basic configurations to get these devices going, but as I haven’t blogged in a while, I wanted to do a quick one on two useful configurations (the second one will come in my next blog post).

I’m a big fan of using serial numbers as a naming convention for all devices as this is an easy, unique identifier.  Setting the serial number as the device name can be easily achieved with Windows and iOS/iPadOS devices using Device Naming Templates in the respective platform Enrollment Profile, but how can I do this with macOS devices?

Normally, a macOS device name is a combination of full name of the first account and the model of mac. For example, my test mac has the device name Paul.Warren’s MacBook Air

Now I could manually change the device name in the Intune Portal.

Note: The device ownership of the mac must be set to Corporate to do this

But I’m not a fan of manual tasks that could be forgotten or subject to human error, so I want the device name change to be something that Intune can configure for me.

Microsoft have provided some really great resources on their Intune GitHub including a script to change the device name.

The existing script if used as is will detect the Mac Model, the serial number and the country, using the current public IP address, and set the device name as “Model Name”-“Serial Number”-“Country”

I only want this script to set the device name to be the serial number so I have edited one line in the script.





In Intune, navigate to Devices – macOS – Shell Scripts and click Add

Use an appropriate name and description – Click Next

Navigate to the location of the shell script

Select the script notification, frequency and maximum retry if script fails options and click Next

Note: I have set the script to run daily to mitigate an employee changing the device name later on.

Select an appropriate Group to deploy this to – I have an Azure AD Dynamic Group that contains all managed macOS devices

Review the summary and click Add

The script is added and will run on macOS devices being managed by Intune.

You can check the status of the script (The log output of this script will be available here also)

The device now shows in Intune with device name that uses Serial Number


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s