Here is a script that i use to rename computers remotely via Jamf. Many computers were not following our standard naming convention, such as computers named "Admin MacBook Pro", etc..
#!/bin/sh
serial=`/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Serial Number (system)/ {print $NF}'`
/usr/sbin/scutil --set ComputerName "CRP${serial}"
/usr/sbin/scutil --set LocalHostName "CRP${serial}"
/usr/sbin/scutil --set HostName "CRP${serial}"
sudo dsconfigad -force -remove -u YourMacBindingAccount -p YourBindingAccountPassword
sudo jamf policy -id 482
#### or with user interaction use this script:
serial=`/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Serial Number (system)/ {print $NF}'`
function machinename () {
osascript <<EOT
tell application "Finder"
activate
set nameentry to text returned of (display dialog "
Please name your computer.
The naming convention is the 3 letter
dept name,
followed by the serial number.
Example:
CRP${base}${serial}
The serial number for this Mac is:
${base}${serial}" default answer "" with icon 2)
end tell
EOT
}
function renameComputer(){
echo "The New Computer name is: $ComputerName"
scutil --set HostName $ComputerName
scutil --set LocalHostName $ComputerName
scutil --set ComputerName $ComputerName
echo Rename Successful
}
ComputerName=$(machinename)
renameComputer
sudo dsconfigad -force -remove -u YourMacBindingAccount -p BindingAccountPassword
sudo jamf policy -id 482
sudo jamf manage
sudo jamf recon
sudo /usr/local/jamf/bin/jamf displayMessage -message "To Join your Computer to our Corp Domain, please re-start your computer."
exit 0