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
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
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.
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.
@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
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.
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.
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.
@cboatwright script working great for us. Had to fix the shebang and change 443 to 8443 in our environment.
i am able to delete all classes by using sis importer.
The second and after sync with ASM didn't import any classes .
We ended up using DbVisualizer Pro and a single line query to get this done.
@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
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!
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
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
}
}
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!
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
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.
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
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
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 @RPSadmin2 from my Mac? Thanks in advance.
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 @RPSadmin2 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
As I mentioned in the first post, just be careful doing this as it will wipe out all your classes in one go.
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.
Brilliant! Easy enough. Appreciate your help tremendously!
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
}
}
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?
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?
I'm not as savvy with powershell, but the port may be the issue...did you try 443 (instead of 8443)?
I'm not as savvy with powershell, but the port may be the issue...did you try 443 (instead of 8443)?
thank you! that was the issue 🙂
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
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.
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!
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.
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?
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.