Delete all classes not imported from ASM

wolfhead
New Contributor III

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?

7 REPLIES 7

mrlowrenz
New Contributor II

Can you give me any tips on how to mass delete classes? 

wolfhead
New Contributor III

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

mrlowrenz
New Contributor II

Thank you very much this worked!

 

sdecook
Contributor

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

 

mrlowrenz
New Contributor II

 

Thank you very much for your help and this solution worked too. 

 

cisco_pete
New Contributor II

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

 

@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.