Script to delete static groups (by name or ID)

RDowson
New Contributor III

I have a number of static device groups that I need to delete (about 500 groups!).
I have all of the exact group names and the group ID's.
Could someone please help me with a script to load in these names or IDs and delete them in a batch?

Thanks in advance!

1 REPLY 1

mm2270
Legendary Contributor III

Something along these lines perhaps? Not tested, but it should work or just need some tweaks.
You will need to of course update the relevant bits like the API username/password and the correct URL. If these are computer groups and not mobile ones, then use computergroups instead of mobiledevicegroups

#!/bin/sh

user="username"
pass="password"
url="https://your.jamfserver.com/JSSResource/mobiledevicegroups/id"

group_ids=(1 3 5 10 12 13 18 20 21 28 35). ## Put all IDs in this array separated by spaces

for ID in "${group_ids[@]}"; do
    echo "Now deleting group id: ${ID}"
    /usr/bin/curl -u "${user}:${pass}" "${url}/${ID}" -X DELETE
done

Alternatively, if the group IDs are all in a file somewhere, you could point the script to that file to read them in instead and loop over each one to delete them.