Skip to main content
Question

Delete all classes not imported from ASM


wolfhead
Forum|alt.badge.img+4

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

Forum|alt.badge.img+1
  • New Contributor
  • 3 replies
  • September 9, 2021

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


wolfhead
Forum|alt.badge.img+4
  • Author
  • Contributor
  • 20 replies
  • September 9, 2021

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


Forum|alt.badge.img+13
  • Contributor
  • 43 replies
  • September 10, 2021

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

 


Forum|alt.badge.img+1
  • New Contributor
  • 3 replies
  • September 10, 2021
wolfhead wrote:

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


Thank you very much this worked!

 


Forum|alt.badge.img+1
  • New Contributor
  • 3 replies
  • September 10, 2021
sdecook wrote:

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

 


 

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

 


Forum|alt.badge.img+3
  • New Contributor
  • 2 replies
  • February 16, 2023
sdecook wrote:

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

 


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

 


Forum|alt.badge.img+13
  • Contributor
  • 43 replies
  • February 16, 2023
cisco_pete wrote:

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.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings