Posted on 04-10-2023 08:35 AM
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!
Posted on 04-10-2023 10:52 AM
try adding this line:
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName "$assetTag"
Posted on 04-10-2023 11:35 AM
Thank you! I will give this a shot. One question, I assume since this is running this with sudo privileges, I would have to modify my API account possibly, or should it be ok?
Posted on 04-10-2023 11:37 AM
it will be fine since the script is running as root.
Posted on 04-10-2023 03:13 PM
Just an aside, I would highly recommend setting up brysontyrrell/EncryptedStrings instead of including your password in plain text. Jamf Pro scripts are downloaded and stored locally when run so any password you include is easily accessible to a user. The benifit here is that an attacker would need access to a local device as well as your Jamf instance to get the credentials.
Posted on 04-11-2023 11:58 AM
Thanks Trent. Curious if there is any more documentation on how to use the encrypted strings? I am new to scripting.
Posted on 04-23-2023 09:19 PM
@DanVT - I was going to suggest you have a serious conversation about the utility of asset tags and naming your computers with them, as I suspect - unless you're paying extra to some vendor to get your Macs' asset tags loaded into Jamf Pro that you've got a manual process and relying on API lookup that is fraught with risk. Better to name based on model and owner or serial number or some other designation you can derive from the device programmatically as opposed to a sticker on the outside - that's for the physical inventory people.