Skip to main content
Question

Computer naming script to pull information from JSS

  • February 14, 2018
  • 3 replies
  • 31 views

Forum|alt.badge.img+10

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

mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • February 14, 2018

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.


Forum|alt.badge.img+20
  • Valued Contributor
  • April 30, 2018

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


Forum|alt.badge.img+10
  • Author
  • Contributor
  • July 13, 2018

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