Asset Tag - Mass edit

spif_spaceman
New Contributor III

Good morning all.

We are attempting to edit several class lists of ipads in JSS version 9.92.
After entering the correct criteria, the search result shows 29 devices. I see an Asset Tag column on the right side, but cannot choose Action button, "Edit Asset Tag" for those 29 devices. Is this possible to do? Otherwise we would have to update the field on those devices one by one. It would allow us to save time and not have to resort to deleting those devices from JSS before we need to. Thanks

15 REPLIES 15

mm2270
Legendary Contributor III

Yeah, I don't think the Asset Tag is something that can be edited en masse using the Action buttons in the JSS. The main reason for this would be that it doesn't make any sense to include it there. Asset tags are typically unique per device, so how would you be able to update them en masse since each one will need its own individual tag?

You'd probably need to use an API script to update each individual record, though its possible someone has a more efficient method. Are you wanting to update them all to the same information? if so, just curious why? I think there are probably better ways to do that, like a custom field Extension Attribute you can apply to all of them for example.

pat_best
Contributor III

Where is the asset tag info coming from? I have done this via the API using a portion of our computer name field to fill the asset tag field. Here is an example:

#!/bin/sh
# The purpose of the script is to add the asset number matching the computername to the asset_tag field
# Define the variables

jssAPIUsername="apiusername"
jssAPIPassword="apipassword"

#Enter in the hostname in the quotes here, replacing https://jss.organization.com:8443 without the trailing slash
jssAddress="https://my.jss.com:8443"


# Do not edit below this line
# -----------------------------------------------------
# This needs to be done for all computers in the environment, so find out how many computers there are.
# get all computers
curl -v -k -u $jssAPIUsername:$jssAPIPassword $jssAddress/JSSResource/computers -X GET > /tmp/allcomputers.xml

# then get the size out of that file
numOfComputers=`cat /tmp/allcomputers.xml | xpath //computers/size |sed s/<size>//g| sed s/<\/size>//g`

#set index to zero
index=0

# Create an XML to put the truncated computername into the asset_tag field
while [ $index -lt $numOfComputers ]
do
#create an xml of a computer by JSS ID
    index=$[$index+1]
    computerid=`cat /tmp/allcomputers.xml | xpath //computers/computer[$index]/id |sed s/<id>//g | sed s/<\/id>//g`
    curl -v -k -u $jssAPIUsername:$jssAPIPassword $jssAddress/JSSResource/computers/id/$computerid -X GET > /tmp/computer.xml

#find the computername from that xml and parse out the asset number
    asset_tag=`cat /tmp/computer.xml | xpath //computer/general/name | sed s/<name>//g | sed s/<\/name>//g | cut -b4-8`

#take the given asset_tag and create an xml to be put to the api

    echo '<?xml version="1.0" encoding="UTF-8"?><computer><general><id>'"$computerid"'</id><asset_tag>'"$asset_tag"'</asset_tag></general></computer>' > /tmp/computercomplete.xml

# Then, take that /tmp/computercomplete.xml and put it in the JSS for each computer
    curl -k -v -u $jssAPIUsername:$jssAPIPassword $jssAddress/JSSResource/computers/id/$computerid -T "/tmp/computercomplete.xml" -X PUT

rm /tmp/computer.xml
rm /tmp/computercomplete.xml

done

#clean up
rm /tmp/allcomputers.xml

Our computer names look like ABC12345-L01-01 where 12345 is our asset tag information. This is edited from a script to populate site data from JAMF.

EDIT: this is for our OS X devices, you would need to sub in the appropriate fields for iOS

krispayne
Contributor

@spif_spaceman @mm2270 I once had to edit asset tags en mass and used jss-assettag-importer from @bradschm. He was fairly responsive to questions and edits on the macadmins slack channel when I was using it.

spif_spaceman
New Contributor III
Are you wanting to update them all to the same information? if so, just curious why?

Yes, we would be placing the same information into the asset tag. We are interested in doing this so that we can ensure that each class has turned in all their ipads. For example, if we have a bin of 30 ipads turned in, we can create a search in JSS to narrow down the results to show just that class, then we would like to edit those 30 ipads with the tag "FORSALE"

pat_best
Contributor III

if you wanted to API script it, all you would need to do is get the full list by JSS ID and cycle through it to PUT the static info into the asset tag field. I haven't used the jss-assettag-importer @krispayne mentioned above. It looks like it does a similar process to what I described above using python. My python skills are terrible but it looks like there are some cool features in there.

mm2270
Legendary Contributor III

As I mentioned before, you might want to at least look at using Mobile Device Extension Attributes as it may be a more appropriate place for this than the Asset Tag field.
Either that, or you can look at the script linked to by @krispayne above. I've not used it myself, so I can't comment on it.

spif_spaceman
New Contributor III
get the full list by JSS ID and cycle through it to PUT the static info into the asset tag field.

Could you expand on this? I'm a newbie and I'm not sure where I would go in JSS to do those steps.

Thanks!

krispayne
Contributor

@pat.best @mm2270 I used it it was when I was doing a JSS migration, so I had a list of known serials and their asset tags from the previous jss. It worked extremely well for me in that instance, and if @spif_spaceman is just going to mass edit based on a known criteria, whether the asset tags are unique or not, seems like it will work swimmingly.

pat_best
Contributor III

let me do some quick building...

spif_spaceman
New Contributor III

Thanks for all the quick responses, everyone!

pat_best
Contributor III

I agree with @krispayne to take a look at the option he linked and @mm2270 has a great idea with the extension attribute and it will offer more flexibility down the road. I am unsure of what you might key the EA on, maybe mm2270 can elaborate a little. Here is what I came up with by editing the above script.... Please test before running.

#!/bin/sh
# The purpose of the script is to add the asset variable to the asset_tag field
# Define the variables

jssAPIUsername="name"
jssAPIPassword="password"
asset="FOR SALE"

#Enter in the hostname in the quotes here, replacing https://jss.organization.com:8443 without the trailing slash
jssAddress="https://my.jss.com:8443"


# Do not edit below this line
# -----------------------------------------------------
# This needs to be done for all mobile devices in the environment, so find out how many computers there are.
# get all mobiledevices
curl -v -k -u $jssAPIUsername:$jssAPIPassword $jssAddress/JSSResource/mobiledevices -X GET > /tmp/alldevices.xml

# then get the size out of that file
numOfDevices=`cat /tmp/alldevices.xml | xpath //mobile_devices/size |sed s/<size>//g| sed s/<\/size>//g`

#set index to zero
index=0

# Create an XML to put asset variable into the asset_tag field
while [ $index -lt $numOfDevices ]
do
#create an xml of a mobile device by JSS ID
    index=$[$index+1]
    deviceid=`cat /tmp/alldevices.xml | xpath //mobiledevices/mobile_device[$index]/id |sed s/<id>//g | sed s/<\/id>//g`
    curl -v -k -u $jssAPIUsername:$jssAPIPassword $jssAddress/JSSResource/mobiledevices/id/$deviceid -X GET > /tmp/device.xml

    #take the given asset_tag and create an xml to be put to the api

    echo '<?xml version="1.0" encoding="UTF-8"?><mobile_device><general><id>'"$deviceid"'</id><asset_tag>'"$asset"'</asset_tag></general></mobile_device>' > /tmp/devicecomplete.xml

    # Then, take that /tmp/devicecomplete.xml and put it in the JSS for each mobile device
    curl -k -v -u $jssAPIUsername:$jssAPIPassword $jssAddress/JSSResource/mobiledevices/id/$deviceid -T "/tmp/devicecomplete.xml" -X PUT

    rm /tmp/device.xml
    rm /tmp/devicecomplete.xml

done

#clean up
rm /tmp/alldevices.xml

Keep in mind, this script will edit ALL of your mobile devices. Editing by device group will look different

mm2270
Legendary Contributor III

In all truthfulness, I only know that EAs can be applied to mobile devices, whereas at one time it wasn't an option. But it looks like unless you are tying it to some LDAP attribute, you might need to create a script to handle this anyway, even for applying an Extension Attribute value. So I don't know how much you would gain by going that route, unless you can find some unique LDAP attribute that it can be tied to. Like for example, if all the users of these iPads are in the same unique AD group or have some other custom AD field applied to them that the other iPad users would not have, you can map to that attribute and have the EA populated by that.

The other options are Pop up and Text field, both of which would be manually applied, or applied via a script similar to the above ones.

EDIT: Meant to also say that I still think an EA field would be the better place for this. That way you can retain all your original Asset Tags (if they have ones applied) and still have the unique string to identify the devices for sale. Once you overwrite the asset tag, there's no real "undo". You'd need to reapply one to each device if for some reason you needed those Asset tags in there.

Jalves
Contributor

I reached out to JAMF support with a similar request and they were able to set me up with an app that uploads and replaces inventory information from a csv file. It's a little easier if you've never used the API before. That's been my go to for correcting and creating large batches of inventory. I'd reach out to your support rep.

spif_spaceman
New Contributor III

@Jalves Thanks for your input.

JesseNCSD
New Contributor III

For anyone searching this thread, when I contacted JAMF support about this, they directed me to a community project I was not aware of:
http://jssmut.weebly.com
https://github.com/mike-levenick/mut/blob/master/README.md