Posted on 08-14-2017 11:01 AM
Not looking to reinvent the wheel, was wondering if anyone out there had a script or other method for mass assigning a certain device group to multiple classes? Right now I have about three dozen classes which need to have the same group of iPads assigned to them. This has to happen for four buildings. Short of doing each by hand was wondering if anyone had a better way or some insight they'd like to share?
Thanks.
Solved! Go to Solution.
Posted on 08-14-2017 12:30 PM
This is pretty easily done with the API. You'll need to compile a .csv list of the class IDs and matching mobile device group IDs to feed into the script, but it will work. There are a few items in the classes API that refer to mobile device groups, but filling in the mobile_device_group_ids one will tell the JSS to populate the others automatically. I've included a script below that will do the job.
#!/bin/sh
TARGET = /Path/to/list.csv
cat $TARGET | while read CLASS GROUP; do
curl -sk -u username:password -H "Content-Type: text/xml" -d "<?xml version="1.0" encoding="ISO-8859-1"?><class><mobile_device_group_ids><id>$GROUP</id></mobile_device_group_ids></class>" https://your.jss.url:8443/JSSResource/classes/id/$CLASS -X PUT
done
Posted on 08-14-2017 12:30 PM
This is pretty easily done with the API. You'll need to compile a .csv list of the class IDs and matching mobile device group IDs to feed into the script, but it will work. There are a few items in the classes API that refer to mobile device groups, but filling in the mobile_device_group_ids one will tell the JSS to populate the others automatically. I've included a script below that will do the job.
#!/bin/sh
TARGET = /Path/to/list.csv
cat $TARGET | while read CLASS GROUP; do
curl -sk -u username:password -H "Content-Type: text/xml" -d "<?xml version="1.0" encoding="ISO-8859-1"?><class><mobile_device_group_ids><id>$GROUP</id></mobile_device_group_ids></class>" https://your.jss.url:8443/JSSResource/classes/id/$CLASS -X PUT
done
Posted on 08-15-2017 07:54 PM
Thank you for this. Once I got my method down for gathering my class IDs (uses the JSS API to export to XML and then process to a CSV) it was easy to build the feeder file.
Posted on 08-16-2017 11:45 AM
That is a handy way to collect input from a CSV. I have a feeling some of my one-off work scripts are going to get a LOT simpler.
Thank You!!
chris :)
Posted on 03-18-2019 07:57 AM
Hi All,
Sorry to revive a dead thread but I'm in exactly the same situation as OP and this script would be a God-send if I could get it to work, I'd hugely appreciate some help :)
We're trying to update a Jamf Cloud instance but when we run the script (having created and defined the CSV of Class IDs and the singular Group ID across all of them) we get this message:
This means the web address is incorrect but I'm wondering if anyone knew the syntax for Jamf Cloud instances when scripting for this?
Thanks!