Skip to main content
Question

Change all machine names to serial number

  • July 27, 2018
  • 4 replies
  • 19 views

rpayne
Forum|alt.badge.img+12

We have a need to rename all managed Macs to their serial number. Is there an easy way to automate this? I'm not finding anything.

4 replies

bmortens115
Forum|alt.badge.img+15
  • Contributor
  • July 27, 2018

Give this a shot. I have this running at enrollment complete for my devices, but you could just run this once per computer.

#!/bin/sh

#get serial number
serial=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')

# Set Hostname using variable created above
echo "Setting computer name to $serial locally..."
scutil --set HostName "$serial"
scutil --set LocalHostName "$serial"
scutil --set ComputerName "$serial"


exit 0

Forum|alt.badge.img+18
  • Honored Contributor
  • July 27, 2018

What you want todo is run a script that does this:

#!/bin/bash

##get serial number
computerName=$(ioreg -c IOPlatformExpertDevice -d 2 | awk -F" '/IOPlatformSerialNumber/{print $(NF-1)}')

#set the host name on several places

/usr/local/bin/jamf setComputerName -name "$computerName"
/usr/sbin/scutil --set LocalHostName "$computerName"
/usr/sbin/scutil --set HostName "$computerName"
/usr/sbin/scutil --set ComputerName "$computerName"
/usr/bin/defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName "$computerName"

/usr/local/bin/jamf recon
exit 0

rpayne
Forum|alt.badge.img+12
  • Author
  • Contributor
  • July 31, 2018

Thanks guys. Is there a way to do in Jamf Pro and then utilize the "enforce machine name in JAMF?"


Forum|alt.badge.img+18
  • Honored Contributor
  • July 31, 2018

You would use the scripts above as part of your policy in Jamf.