Renaming a Mac - JAMF Casper Suite

2015-04-10 17:22 PDT

Long ago an unfortunate choice was made at my workplace; to name computers after the user that it is assigned to. I prefer that computer names be entirely user agnostic - preferably names after and asset tag number. THe excuse for this bad behavior: “we have always doen it this way.”

Recently we have started using JAMF’s Caper Suite to manage our Macs, and one of the things we desired to do was get these machines bound to Active Directory so that we could take advantage of kerberized services and LDAP authentication. To do that (and stick with the ridiculous naming policy) we put together a script that JAMF runs on a machine prior to binding it to AD.

The issue we had was getting the computers to name themselves after the proper username, rather than some of the names that had been created automatically like “Local’s MacBook Air” To that end we first populated JAMF with a list of users and their usernames. We are using JAMF Cloud, their hosted service, so we don’t have JAMF connected to AD for LDAP authentication, so we created those users manually.

Next, when a computer gets enrolled in JAMF we assign it to a user in the JAMF console. This provides our script with all it needs to run. The key line is this one:

curl -sSk -H "Accept: application/xml" -u api:$TOKEN  $BASEURL/JSSResource/computers/match/`system_profiler SPHardwareDataType | grep Serial | awk '{print $NF}'` > $XMLFILE

It will query JAMF for the assigned username, later that username gets munged to come up with a same computer name that is then written to the various host names of the computer. Additionally we have some people who have more than one computer assigned to them, so we took the last for characters of the mac address for en0, and appended that to the end of the computer name before binding - this seems like a safe bet to ensure that all the names are unique.

Here is the whole script