Posted on 01-29-2018 02:20 PM
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
Posted on 01-30-2018 11:27 AM
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.
Posted on 09-26-2018 03:17 PM
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.
Posted on 09-27-2018 09:13 AM
@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
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
Posted on 10-09-2018 10:11 AM
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.
Posted on 08-08-2019 11:45 AM
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.
Posted on 08-08-2019 12:02 PM
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.
Posted on 08-13-2019 10:08 AM
@cboatwright script working great for us. Had to fix the shebang and change 443 to 8443 in our environment.
Posted on 08-27-2019 04:53 PM
i am able to delete all classes by using sis importer.
The second and after sync with ASM didn't import any classes .
Posted on 11-21-2019 09:07 AM
We ended up using DbVisualizer Pro and a single line query to get this done.
Posted on 08-27-2021 06:43 AM
Hello,
Can you please share what is the query you used to delete all classes
Thanks
Posted on 01-10-2020 11:45 AM
@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
Posted on 07-01-2020 07:50 AM
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!
Posted on 07-01-2020 12:09 PM
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
08-05-2021 11:16 AM - edited 08-05-2021 12:48 PM
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.
08-05-2021 11:52 AM - edited 08-05-2021 12:46 PM
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
Posted on 11-04-2020 09:26 AM
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
}
}
Posted on 08-17-2021 12:04 PM
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?
Posted on 08-17-2021 12:10 PM
I'm not as savvy with powershell, but the port may be the issue...did you try 443 (instead of 8443)?
Posted on 08-17-2021 12:11 PM
thank you! that was the issue 🙂
Posted on 12-07-2020 06:21 AM
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!
Posted on 08-13-2021 05:16 AM
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.
08-17-2021 11:26 AM - edited 08-17-2021 11:31 AM
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
As I mentioned in the first post, just be careful doing this as it will wipe out all your classes in one go.
Posted on 08-17-2021 11:34 AM
Brilliant! Easy enough. Appreciate your help tremendously!
Posted on 09-29-2021 05:32 PM
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!
Posted on 10-07-2021 10:57 AM
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?
Posted on 08-04-2022 05:42 PM
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?
Posted on 08-04-2022 05:52 PM
Posted on 08-04-2022 06:18 PM
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 ~ %
Posted on 02-05-2024 10:37 AM
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:
As I mentioned in the first post, just be careful doing this as it will wipe out all your classes in one go.
Posted on 07-02-2024 05:54 AM
I am getting a "-:1: parser error : Document is empty" error. Any ideas?
9 hours ago
Hey @RPSadmin2, Thanks for the detailed directions. All seemed to be running smoothly, but when I run the sh file it just returns the response.
Downloading list of class IDs...
Then goes back to the command prompt. Its like nothing is running after printing that on the screen.
We are running JAMF Version11.3.0-t1707837736
Thanks,
Bill