Posted on 07-27-2018 09:47 AM
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.
Posted on 07-27-2018 09:58 AM
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
Posted on 07-27-2018 09:59 AM
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
Posted on 07-31-2018 10:13 AM
Thanks guys. Is there a way to do in Jamf Pro and then utilize the "enforce machine name in JAMF?"
Posted on 07-31-2018 10:15 AM
You would use the scripts above as part of your policy in Jamf.