Computer naming script to pull information from JSS

jgwatson
Contributor

Looking for a computer naming script to pull information from the General Field within each computers record in JAMF. User and Location = Building, From the General tab = Asset Tag, Model - from the hardware tab. Is this possible? Can someone share something close to it please? Thanks

<Building><Model><Asset Tag>

3 REPLIES 3

mm2270
Legendary Contributor III

It sounds like you need an API script to pull these strings, yes? I'm not clear on the end purpose of it, but, does something like this get you most of the way there?

#!/bin/bash

apiUser="apiaccount"
apiPass="apipassword"
jssURL=$(defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url)

macUDID=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformUUID/{print $4}')

macData=$(curl -H "Accept: application/xml" -sfku "${apiUser}:${apiPass}" "${jssURL}JSSResource/computers/udid/${macUDID}/subset/general&location&hardware")

macBuilding=$(xpath '/computer/location/building/text()' <<< "$macData")
macAssetTag=$(xpath '/computer/general/asset_tag/text()' <<< "$macData")
macModel=$(xpath '/computer/hardware/model/text()' <<< "$macData")

echo "Building = $macBuilding"
echo "Asset Tag = $macAssetTag"
echo "Model = $macModel"

You will need to replace the apiUser and apiPass strings with either hardcoded values, or use script parameters passed to them for the credentials.

mconners
Valued Contributor

@jgwatson did you ever get this working? I have an almost identical need as this. Just curious what you came up with.

jgwatson
Contributor

@mconners really sorry for the late reply - no dice I'm afraid. Gave up on it.