Hi All,
I am fairly new to scripting and am humbly requesting help.
We use the following script to rename the Computer Name to Asset Name(via what is uploaded in Inventory Preload). What I found, is I also need this script to enable Dynamic Host Name and set that name to that same Asset Name. I cannot get that last piece to work and believe it was incorrect, so I have removed it and asking the community.
Here is the script I am using to set Computer Name to Asset, which has been working great. I am hoping to be able to use this same script and add the piece to enable naming of the Dynamic Host name as well.
#!/bin/bash
#set the variables for the server and API account
jssUser=UserName
jssPass=PW
jssHost=https://tenantname.jamfcloud.com
#get the serial number
serialNumber="$(ioreg -l | grep IOPlatformSerialNumber | sed -e 's/.*\\"\\(.*\\)\\"/\\1/')"
#get the asset tag from jamf
assetTag=$(/usr/bin/curl -H "Accept: text/xml" -sfku "${jssUser}:${jssPass}" "${jssHost}/JSSResource/computers/serialnumber/${serialNumber}/subset/general" | xmllint --format - 2>/dev/null | awk -F'>|<' '/<asset_tag>/{print $3}')
# set computer name
if [ "$assetTag" == "" ]; then
echo "Asset Tag is empty. Exiting..."
exit 1
else
/usr/sbin/scutil --set HostName "$assetTag"
/usr/sbin/scutil --set LocalHostName "$assetTag"
/usr/sbin/scutil --set ComputerName "$assetTag"
fi
/usr/local/jamf/bin/jamf recon
I appreciate any help!