Posted on 02-26-2021 08:08 AM
Hello to all. I'm using the following naming script to manually rename a computer. I renames the computer fine but it doesn't change the name in JAMF. It still is just listed as "iMac". Any thoughts?
sleep 30
ComputerName=`/usr/bin/osascript <<EOT
tell application "System Events"
activate
with timeout of 86400 seconds
set ComputerName to text returned of (display dialog "Please Input Computer Name" default answer "" with icon 2)
end timeout
end tell
EOT`
echo $ComputerName
sudo scutil --set HostName $ComputerName
sudo scutil --set LocalHostName $ComputerName
sudo scutil --set ComputerName $ComputerName
echo "Rename Successful"
sudo /usr/local/bin/jamf recon
sleep 10
exit -0
Posted on 02-26-2021 08:29 AM
First off, you can drop all of the sudo
's in your script. Assuming the entire script is being called in a Jamf policy, it's already running as root, so those aren't needed.
Second, in my own computer renaming script, I do the following 3 commands after applying the new name
/usr/bin/killall -HUP mDNSResponder
/usr/bin/killall mDNSResponderHelper
/usr/bin/dscacheutil -flushcache
I then wait about 3 seconds sleep 3
, before I collect inventory back to Jamf. I found that the old computer name tends to stick around very annoyingly unless those processes are restarted and the cache is flushed and I give it a few seconds before telling Jamf what the new name is. Now, it's possible doing all 3 above is overkill; maybe only one or two are needed; but I keep all 3 there to be extra sure. It has been working well for me so I'm sticking with it for now.
Give that a try and see if it helps you too.