Rename Macs
Summary
This script will enforce naming Macs based upon their serial numbers.
In addition to using the serial number to form the bulk of the naming convention, the script will also determine wether a laptop or desktop Mac is being renamed. If the computer being renamed is a laptop then the serial number will be prefixed with “ML-” representing “Mac Laptop“. If the computer is determined to be a desktop computer then the serial number will be prefixed with “MD-” to signify “Mac Desktop“.
Script Content
#!/bin/zsh
islaptop=`/usr/sbin/system_profiler SPHardwareDataType | grep "Model Identifier" | grep "Book"`
if [ "$islaptop" != "" ]; then
newmacname=`system_profiler SPHardwareDataType | grep "Serial Number (system)" | sed 's/Serial Number (system): /ML-/'`
else
newmacname=`system_profiler SPHardwareDataType | grep "Serial Number (system)" | sed 's/Serial Number (system): /MD-/'`
fi
scutil --set ComputerName $newmacname
scutil --set HostName $newmacname
scutil --set LocalHostName $newmacname
defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName $newmacname
rm -f "$islaptop"
rm -f "$newmacname"
Concluding Comments
By implementing this naming convention when working with a large number of Macs will ensure that all computer names are unique. In addition it will allow for easy identification of wether a Mac is a laptop or desktop model.