Delete all classes not imported from ASM

wolfhead
New Contributor

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?

5 REPLIES 5

mrlowrenz
New Contributor II

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

wolfhead
New Contributor

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.