Hello all! I'm new to JAMF. We have installed Mac Mini machines to be content caches for our iPads in the school system. They are set to configure themselves when they are plugged into the network and powered up. The default name is mac mini. I go and manually rename each one after it comes up. But for some reason, a couple of days later, the name has reverted to mac mini. I look in the history in JAMF and it only shows when it was created and each time I have renamed it. Any logs I can look at other than the history for the machine? Any ideas?
Mini Mac Computer Name Reverts to Default

Best answer by AJPinto
Whilst the script provided by @AJPinto is valid, it is unnecessarily complex and also fails to update the matching information in Jamf Pro inventory.
The value you want to set the name to will depend on your own choices - as an example I have a script which reads the name of the 'asset' from an asset database called SnipeIT but for simplicity I will use the Mac serial number as an example. Therefore the core of the script will be as follows.
#!/bin/bash
#
serialNumber=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
/usr/local/bin/jamf setComputerName -name "$serialNumber"
exit
The jamf command not only sets all three computer names in one but also sends the new name to Jamf Pro to update the inventory record.
We are doing basically the same thing, just backwards. I prefer to write my scripts to be MDM agnostic, that way they can be run locally without issue and not needing JAMF. The JAMF recon at the end of my script, updates JAMF as to what the devices hostname is.
My script is a little long, but mainly because it uses a lot of variables, comments and "error" checking. The bones of my script is 3 lines. If you are not setting all 3 of these, you are not seeing the hostname correctly.
scutil --set ComputerName "$serialNumber"
scutil --set HostName "$serialNumber"
scutil --set LocalHostName "$serialNumber"
The rest of the script is gathering what the serial number is, and making sure each of the 3 lines above actually need to be run with a ton of comments. This way you are not needlessly making changes. With a finally check to make sure the hostname actually changed and it will error if the hostname did not change.
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.