Jamf computer renaming using JSS assigned user

We want to name our Macs based on the user that we assign them to. To create some uniqueness, we also append part of the MAC address of the computer, creating computer names like "mknowles-e256". We then use Jamf to bind to our Active Directory domain.

That's great, but before the computer is bound we don't have the username, and can't rely on the local username; there's no standard out there (for us) on what those user names may be.

We do, however, assign the computers to an appropriate username inside Jamf. We found that the scripts didn't always send this username down to the computer. Using the "$3" username parameter for scripts seemed to work only occasionally, and not in a way that made sense to us.

To get the username, a new script was born. With some ideas and help from Jamf support and some back and forth with Bill at work, we have something working. This method returns all the "user and location" information from the Jamf computer entry, though we currently are just using the assigned username.

Take the following couple of lines of script:

mkdir -p /tmp/jamf/

# get location data from jss
curl -sSk -H "Accept: application/xml" -u api:apipassword https://yourserver.jamfcloud.com:443/JSSResource/computers/match/`system_profiler SPHardwareDataType | grep Serial | awk '{print $NF}'` > $XMLFILE

This gets the "user and location" section of the computer and saves it to the temp folder as an xml file. This in a script can then be used to get up-to-date info that can be parsed into, for us, the username and eventually the computer name we want the computer to have.

All it does is go to the Jamf server and pulls the data as a web page. It's not all that elegant, but it's been reliable.