Shared iPad Classes and Mobile Devices Groups (Script)

jsmillie
New Contributor III

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.

1 ACCEPTED SOLUTION

bburdeaux
Contributor II

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

View solution in original post

4 REPLIES 4

bburdeaux
Contributor II

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

jsmillie
New Contributor III

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.

cdenesha
Valued Contributor II

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 :)

Ecco_Luke
Contributor II

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:

  • <title>Status page</title> </head> <body style="font-family: sans-serif;"> <p style="font-size: 1.2em;font-weight: bold;margin: 1em 0px;">Not Found</p> <p>The server has not found anything matching the request URI</p> <p>You can get technical details <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.5">here</a>.<br> Please continue your visit at our <a href="/">home page</a>. </p> </body> </html>*

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!