Skip to main content

Hey all,



Anyone know if there is a way to get the Inventory > General > Asset Tag of machine read from the jss and get that into the ARD fields?



I use the 4 ARD fields of my machines.
ARD 1 is populated by a script the reads the IOREG > Machine Model
ARD 2 is populated by a script that reads the jamf version
ARD 3 is manually typed in with the Build Date
ARD 4 would like to populate by reading back the Inventory > General > Asset Tag of machine.



Here is the script:



#!/bin/bash

#Set Field 1 to MachineModel
machineModel=`ioreg -l | grep product-name | awk '{print $4}' | tr -d '<">'`
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -computerinfo -set1 -1 $machineModel

sleep 10

#Set Field 2 to JAMF Binary version
JSSVERSION=`jamf version`
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -computerinfo -set2 -2 $JSSVERSION


Thanks in advance as always.



-pat

via the API... do a GET for asset_tag... cycle it through all the computer_id's... store that info in a temp .csv document then put it from the temp document into the asset tag field of choice...



so the logic would be...



curl -kvu https://yourJSS.com:8443 -T GET > /temp/asset_tag_and_computer_id.csv



read from /temp/asset_tag_and_computer_id.csv



curl -kvu https://yourJSS.com:8443 -T POST


An alternative, also using the API, you could set up a script to run in a one time policy against each Mac to use an API account to pull its own asset tag, store that into a variable, and then pipe that back into a ARDAgent kickstart command to set field 4 for that Mac.



Here's a framework for this. The below should work with either version 8.x or 9.x of Casper suite, since they both can use the MAC address as an item to locate a Mac in the db. Version 9 can also accept serial #, UDID and a few others. Version 8 was a little more limited.



#!/bin/bash

MACaddy=$( networksetup -getmacaddress en0 | awk '{print $3}' | sed 's/:/./g' )
echo "{MACaddy}"

ASSETTAG=$( curl -s -k -u apiuser:apipass https://yourjss.server.com/JSSResource/computers/macaddress/$MACaddy 2>&1 | xpath /computer/general/asset_tag[1] | awk -F'[>|<]' '{print $3}' )
echo "${ASSETTAG}"

/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -computerinfo -set4 -4 "${ASSETTAG}"


Just customize the "apiuser", "apipass" and JSS server address items to your environment.


@mm2270 I had to add the port 8443 and $ but this works great thanks for posting.



#!/bin/bash

MACaddy=$( networksetup -getmacaddress en0 | awk '{print $3}' | sed 's/:/./g' )
echo "${MACaddy}"

ASSETTAG=$( curl -s -k -u apiuser:apipass https://yourjss.server.com:8443/JSSResource/computers/macaddress/$MACaddy 2>&1 | xpath /computer/general/asset_tag[1] | awk -F'[>|<]' '{print $3}' )
echo "${ASSETTAG}"

/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -computerinfo -set4 -4 "${ASSETTAG}"

Awesome peeps!!!
Works like a charm!



Thank you very much,



-pat