Mass delete all classes Imported with Apple School manager

jgwatson
Contributor

We are after changing the naming convention for classes imported with ASM. Is there a way to mass delete the classes in there now?

Thanks

29 REPLIES 29

bburdeaux
Contributor II

You can use the SIS Importer to delete all existing classes. You'll just need to create an export with no source file and the "Delete Existing Classes" box checked. It takes a while for it to delete them all, depending on how many classes you have, but this is the easiest way to delete all of the classes.

hhiggins
New Contributor

Is this still the best way to delete classes? I need to delete 1400 or so. So this looks very appealing. I am running 10.5, will this work with it? I was given a script by Jamf to do it and it won't run for some reason. Something about special characters in the password.

cboatwright
New Contributor III

@hhiggins I did this recently myself via a short script, worked very well after discovering that the api does not like some special characters in passwords. Find the classid for the ones you wish to delete using the get /classes from the Jamf API. Plug those start and end IDs in where the script specifies for n

!/bin/bash

jssUser="Username"
jssPass="Password"
jssURL="https://yourdomain.jamfcloud.com:443/"

for n in {1..100}
do
curl -kvu $jssUser:$jssPass ${jssURL}JSSResource/classes/id/$n -X DELETE
done

ktrojano
Release Candidate Programs Tester

We delete all classes each summer and I still use the SIS Importer using the method described above by bburdeaux. It's easy to use and consistently works.

Kimberly Trojanowski

bcassidy
New Contributor II

I tried this, but got this message: "Connection finished: 0 of 1 plug-ins were successful" and no classes were deleted. I've attached screenshots. Any help greatly appreciated.
d05cd06257cb466a856831f9f264d800
bb270606a821444183186107829c7e00
d18d7cd0022840cf8aab82e0c00d147a
d7d0e0e50b6949e1b29fc766c238d98b

bcassidy
New Contributor II

Never mind. I got it to work. I had to add port 443 to the URL because if I didn't it kept defaulting to 8443 when I saved it.

chris_miller
Contributor

@cboatwright script working great for us. Had to fix the shebang and change 443 to 8443 in our environment.

locolyric
New Contributor II

i am able to delete all classes by using sis importer.
The second and after sync with ASM didn't import any classes .

ITHoneyBadger
New Contributor III

We ended up using DbVisualizer Pro and a single line query to get this done.

Hello,

Can you please share what is the query you used to delete all classes

Thanks

RPSadmin
New Contributor

@cboatwright For those that might find it useful I modified your code above so that you don't have to determine the range of your classes. This will automatically find the IDs of all the classes you have created and delete all of them. Be careful with this as it will delete everything, but, I've found it really useful as a quick way to clear everything out before re-importing from ASM.

#!/bin/bash
jssUser="Username"
jssPass="Password"
jssURL="https://yourdomain.jamfcloud.com:443/"

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
    curl -kvu $jssUser:$jssPass ${jssURL}JSSResource/classes/id/$n -X DELETE
done

cboatwright
New Contributor III

It is that time of year again, and just thought I would chime in with some updates on this process! I have now tried @RPSadmin script (works great for those wanting to simply delete all!) and the SIS Importer tool. Unfortunately it seems the SIS Importer tool does not like macOS Catalina, and possibly Mojave too - good thing it is Java-based so I just dumped it on my PC and started running from there.

Here is where I met my roadblock this year - SIS Importer and scripts both ran "successfully" but my 6000 classes were not going away! Finally I logged into the local admin service account we use for these things (and when LDAP is down) where I noticed it was in site view for just 1 of our schools. I switched it to full view, fired up SIS Importer again and low and behold it actually began deleting classes! That's just nuts... but not more nuts than Jamf STILL NOT having this functionality built-in!

twall
New Contributor III

We use both ASM created classes (primarily in upper grades) as well as manual ones (in lower grade class sets). I've modified the above script to check each class for its source, and if source = N/A skips it, while deleting any classes with a source of "Apple School Manager". There is probably a better way to do this, but this does seem to work.

#!/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, skipping..."
    elif [[ $source = "Apple School Manager" ]] ; then
        echo "Class $n created by ASM, deleting..."
        curl -s -k -u ${jssUser}:${jssPass} ${jssURL}/JSSResource/classes/id/${n} -X DELETE
    fi
done

exit 0

Sandy
Valued Contributor II

JamfCloud Version 10.30.3

and running it on a Big Sur laptop....

I would like to delete my 900+ ASM classes but leave my manual classes intact.

Sandy
Valued Contributor II

Ran below (subbing in my user, PW and URL)

and got this return:

Downloading list of class IDs...

-:10: parser error : Opening and ending tag mismatch: br line 8 and p

</p>

    ^

-:11: parser error : Opening and ending tag mismatch: p line 8 and body

</body>

       ^

-:12: parser error : Opening and ending tag mismatch: body line 5 and html

</html>

       ^

-:12: parser error : Premature end of data in tag html line 1

</html>

 

#!/bin/bash
jssUser=“username”
jssPass=“password”
jssURL="https://my.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, skipping..."
elif [[ $source = "Apple School Manager" ]] ; then
echo "Class $n created by ASM, deleting..."
curl -s -k -u ${jssUser}:${jssPass} ${jssURL}/JSSResource/classes/id/${n} -X DELETE
fi
done

exit 0

cbrewer
Valued Contributor II

Tossing a PowerShell class deletion script in here as well. The Invoke-RestMethod cmdlet in PowerShell makes working with xml and json pretty painless.

# Use the Jamf Pro API to delete all classes
$jssURL = "https://jamf.example.com:8443"

$ErrorActionPreference = "Stop"

$creds = Get-Credential

$url = "$jssURL/JSSResource/classes"

# Force TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$jamfClassesXml = Invoke-RestMethod -Uri $url -Credential $creds

Write-Host "$($jamfClassesXml.classes.size) classes found"
Write-Host "----------------------------------------"

$confirmation = (Read-Host 'Delete ALL Classes? (Y/N) [N]').ToLower()
if ($confirmation -eq 'y') {
  foreach ($class in $jamfClassesXml.classes.class) {
    Write-Host "Deleting class $($class.id)"
    $return = Invoke-RestMethod -Uri "$urlid$($class.id)" -Credential $creds -Method Delete
  }
}

mcneillcm
New Contributor II

hey! I am new to PowerShell and I am getting an "Invoke-Restmethod : Unable to connect to the remote server"

I have updated the commands for our JSS URL and credentials for our API account. Anything else I can try to fix it? 

RPSadmin2
New Contributor II

I'm not as savvy with powershell, but the port may be the issue...did you try 443 (instead of 8443)?

mcneillcm
New Contributor II

thank you! that was the issue 🙂 

JayDuff
Contributor II

Thank you, @cbrewer!

Working from home, and my Windows box is WAY faster than my Mac.

ASM munged everything, and created duplicate accounts with the same Roster associated, so I have to clean up about 50 user accounts. This will make it possible to do so in a few hours instead of a few days! Thank you again!

robert_petitto
New Contributor III

I'm a complete newbie when it comes to scripting. I've been using the SIS import tool for years, but this year I cannot. How do I run the script proposed by @RPSadmin from my Mac? Thanks in advance.

Hi!  I'm RPSadmin from above - the new push to jamf id seems to have forced me to create a new account - guess I'll have to figure out how to merge them 🙂

In any event, to answer your questions, you do the following to run the script on a mac

  1. Open text edit and create a new file.
  2. Go to Format > Make Plain Text
  3. Copy and Paste the script from above, don't forget the line that says "#!/bin/bash"
  4. Change the 2nd, 3rd, and 4th lines so that they show the correct username, password, and URL.
  5. Save the file and quit.
  6. Find the file and change the extension to .sh instead of .txt
  7. Open terminal and type in "sudo chmod u+x /path/to/file" swapping out "/path/to/file/" with the path to the file and excluding the quotation marks.  Note that you can drag and drop the file into the terminal window in order to get the correct path, this is generally the easiest way to make sure it is correct.
  8. Hit enter.  It should ask for your password, go ahead and enter it.  You wont see it as you type, but it is being entered.
  9. Once complete drag and drop the file into terminal again, without sudo chmod u+x so that it just shows the path to the file.  Hit enter and it should execute.  If it doesn't work you may have to put sudo before the file path, but that shouldn't be necessary.

As I mentioned in the first post, just be careful doing this as it will wipe out all your classes in one go.

Brilliant! Easy enough. Appreciate your help tremendously!

This script worked beautifully.  I have been going back and forth with jamf support all day and everything they send did not work.  Thanks so much!

Thanks for the steps, I greatly appreciate them.  Unfortunately, I am getting a "-:1: parser error : Document is empty" error.  Any thoughts on what this error means and how to resolve it?

For some reason, I keep getting 

***********

scrowell@SCROWELL-MBP ~ % sudo chmod u+x sudo /Users/scrowell/Desktop/DeleteAllClasses.sh 

Password:

Sorry, try again.

*************

Not sure what's going on. My account authenticates to jamf through LDAP so I tried using a standard user in jamf that has admin privileges as well without luck. I first used my account in the SH file and the terminal prompt then I tried using the standard account. Any suggestions?

Sandy
Valued Contributor II
Hi,

What you’re doing with this step is changing your script permissions to be
executable. You’re using sudo on your computer so it wants your local user
password ( provided that user is a sudoer)
Hope this helps!
Sandy

--
Sandy Hinding (she/her)
iOS/OSX Systems Administrator
ISD # 197-West St. Paul-Mendota Heights-Eagan Schools
sandy.hinding@isd197.org
651-403-8400

scrowell
New Contributor

Makes sense. I did that but accidentally screwed up the command and was prompted for the pwd. Then I did it properly (I think) but got no results. All of the classes are still present.

*********

scrowell@SCROWELL-MBP ~ % sudo chmod u+x sudo /Users/scrowell/Desktop/DeleteAllClasses.sh

Password:

chmod: sudo: No such file or directory

scrowell@SCROWELL-MBP ~ % sudo chmod u+x /Users/scrowell/Desktop/DeleteAllClasses.sh      

scrowell@SCROWELL-MBP ~ % sudo chmod u+x /Users/scrowell/Desktop/DeleteAllClasses.sh 

scrowell@SCROWELL-MBP ~ %

RPSadmin2
New Contributor II

For anyone finding this thread in the year 2024 -

 

There was a small typo in my script above which wasn't causing issues before but is now.  This is the corrected script:

 

 

#!/bin/bash
jssUser="Username"
jssPass="Password"
jssURL="https://yourdomain.jamfcloud.com:443"

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
	curl -kvu $jssUser:$jssPass ${jssURL}/JSSResource/classes/id/$n -X DELETE
done

 

 

Directions on how to implement the script remain the same, however.  I'll reprint them here so everything is in one place:

  1. Open text edit and create a new file.
  2. Go to Format > Make Plain Text
  3. Copy and Paste the script from above, don't forget the line that says "#!/bin/bash"
  4. Change the 2nd, 3rd, and 4th lines so that they show the correct username, password, and URL.
  5. Save the file and quit.
  6. Find the file and change the extension to .sh instead of .txt
  7. Open terminal and type in "sudo chmod u+x /path/to/file" swapping out "/path/to/file/" with the path to the file and excluding the quotation marks.  Note that you can drag and drop the file into the terminal window in order to get the correct path, this is generally the easiest way to make sure it is correct.
  8. Hit enter.  It should ask for your password, go ahead and enter it.  You wont see it as you type, but it is being entered.
  9. Once complete drag and drop the file into terminal again, without sudo chmod u+x so that it just shows the path to the file.  Hit enter and it should execute.  If it doesn't work you may have to put sudo before the file path, but that shouldn't be necessary.

As I mentioned in the first post, just be careful doing this as it will wipe out all your classes in one go.