Posted on 09-09-2021 08:04 AM
I've found we have about 1500 orphan classes from the previous year which were not cleaned up in our SIS before the import happened for this year.
I know how to mass delete all classes using a script but I only want to delete the ones marked as N/A - is that possible?
Posted on 09-09-2021 08:42 AM
Can you give me any tips on how to mass delete classes?
Posted on 09-09-2021 11:56 AM
for n ({1..9000}); do curl -kvu user:pass https://domain.jamfcloud.com/JSSResource/classes/id/$n -X DELETE; done;
The n number can be seen on a class webpage to give an idea of the range, put in a user and pass that can access jamfcloud and change the domain to your domain. You need curl installed but this runs and works
Posted on 09-10-2021 07:27 AM
Thank you very much this worked!
Posted on 09-10-2021 05:20 AM
I had this script laying around. It was originally intended to delete classes created by ASM and leave manual ones alone. I just switched the if statements around. Keep in mind this will delete manual created classes. If your teachers have made their own it will remove those as well.
The script is not mine so make sure you test it first.
#!/bin/bash
jssUser="apiUser"
jssPass="apiPassword"
jssURL="https://your.jamf.url:8443"
echo "Downloading list of class IDs..."
ids+=($(curl -X GET -s -k -u ${jssUser}:${jssPass} ${jssURL}/JSSResource/classes | xmllint --format - | awk -F'>|<' '/<id>/{print $3}' | sort -n))
for n in "${ids[@]}"; do
source=$(curl -X GET -s -k -u ${jssUser}:${jssPass} ${jssURL}/JSSResource/classes/id/${n} | xmllint --format - | awk -F'>|<' '/<source>/{print $3}')
if [[ $source = "N/A" ]] ; then
echo "Class $n manually created, deleting..."
curl -s -k -u ${jssUser}:${jssPass} ${jssURL}/JSSResource/classes/id/${n} -X DELETE
elif [[ $source = "Apple School Manager" ]] ; then
echo "Class $n created by ASM, skipping..."
fi
done
exit 0
Posted on 09-10-2021 07:41 AM
Thank you very much for your help and this solution worked too.
Posted on 02-15-2023 06:16 PM
Hello, I am very new to Scripting, how do I run this script, where do I run this script?
i have over 700 classes to delete, any assistance will be grateful
thanks
Posted on 02-16-2023 04:40 AM
@cisco_pete Are you wanting to remove ALL classes, or manually created classes?
For the script you will need to copy it into a text editor, alter the variables and save it as a .sh file. Then launch terminal and you will probably have to make the script executable. I usually run "chmod u+x path to script" to make it executable. Then when you want to run it type ./PathToFile.sh and it should kick off.
Someone might have a more efficient way but this is what I have been doing with scripts.