Setting the asset tag as the hostname

alexmcclements
Contributor

Playing around with NetInstall and Recon to re-image machines with High Sierra, this works reasonably well but the issue I am stuck with is setting the hostname for the machine (the system we use predates me), with Recon I can specify the asset tag but not the hostname from the GUI (this process is for our techs who want to do as little as possible).

I was wondering if anyone new of a way of setting the hostname to be the same as the asset tag.

I thought I might be able to call the asset tag name from JAMF using the jamf binary and then I could use that as part of a script but this doesn't appear to be possible.

3 REPLIES 3

Look
Valued Contributor III

Do you have your asset tags listed against the serial number in a database somewhere? We query the our asset DB with the serial number and it returns the asset tag along other information (we actually have the machine name in there as well).

alexmcclements
Contributor

We don't, up until High Sierra we were using DeployStudio and we could supply it with hostname mapped to serial number. Unsure of how we can do that with JAMF.

Thanks for the reply.

joshuasee
Contributor III

One tactic I went with before we went to just using the serial number was to create separate Prestage enrollments for each machine by cloning, changing the AD name each time to match the asset tag, and then having a policy rename the computer according the the AD name.

If that is infeasible, you can create an API account and have the computer look up its asset tag.

Relevant excerpts for looking up the asset tag via the API:

#!/bin/bash
serialnum=$(/usr/sbin/ioreg -c IOPlatformExpertDevice -d 2 | /usr/bin/awk -F" '/IOPlatformSerialNumber/{print $(NF-1)}') || { /bin/echo "Failed to get serial number."; exit 1; };

compinfopath=$(/usr/bin/mktemp -t ${serialnum}) || { /bin/echo "Failed to create info file."; exit 1; };

/usr/bin/curl -s -S -K -H "Accept: application/xml" -u apiusername:apipasswd "${jss_url}JSSResource/computers/serialnumber/${serialnum}/subset/Location&Extension_attributes" -o "${compinfopath}" || { /bin/echo "Failed to pull inventory info."; exit 1; };

assettag=$(/usr/bin/xmllint --xpath '/computer/general/asset_tag' ${compinfopath} | /usr/bin/awk -F '<[a/]+sset_tag>' '{print $2}');