Posted on 07-12-2023 06:10 AM
Here is a script that will remove all class data from your instance.
If you use macOS' TextEditor, be sure to Convert to Plain Text.
Ensure that the file is saved as .sh
I hope this helps!
Have a great day and be well!
Here is the script:
#!/bin/bash
####################################################################################################
#
# THIS SCRIPT IS NOT AN OFFICIAL PRODUCT OF JAMF SOFTWARE
# AS SUCH IT IS PROVIDED WITHOUT WARRANTY OR SUPPORT
#
# BY USING THIS SCRIPT, YOU AGREE THAT JAMF SOFTWARE
# IS UNDER NO OBLIGATION TO SUPPORT, DEBUG, OR OTHERWISE
# MAINTAIN THIS SCRIPT
#
####################################################################################################
#
# DESCRIPTION
# This script retrieves class information from the JAMF Pro RESTful API, saves it as an XML file,
# and then uses that XML file to delete the classes.
# Requires a user that has READ and DELETE privileges for Classes.
#
####################################################################################################
#
# DEFINE VARIABLES & READ IN PARAMETERS
#
####################################################################################################
echo "#####################"
echo "###!!! WARNING !!!###"
echo "#####################"
echo "This script will retrieve class information from the JAMF Pro server and delete all classes."
echo "Please ensure you have a database backup."
echo "There is no magic undo button other than restoring to a backup when the classes were in existence."
read -p "Are you sure you want to continue? [ y | n ] " answer
if [[ $answer != 'y' ]]; then
echo "Exiting script!"
exit 1
fi
read -p "Jamf Pro URL: " server
read -p "Jamf Pro Username: " username
read -s -p "Jamf Pro Password: " password
echo ""
# Trim the trailing slash off if necessary
if [ "${server: -1}" == "/" ]; then
server="${server%?}"
fi
# Add protocol and specify port 443
server="https://${server}:443"
# Base64 encode the username and password for basic authentication
auth=$(echo -n "$username:$password" | base64)
# Filename for the XML file
xmlFile="classes.xml"
echo "Retrieving class information..."
curl -s -H "Authorization: Basic $auth" -H "Accept: application/xml" "$server/JSSResource/classes" -o "$xmlFile"
echo "Deleting classes..."
classIDs=$(xmllint --xpath "//id/text()" "$xmlFile")
for classID in $classIDs; do
echo "Deleting class with ID: $classID"
curl -s -H "Authorization: Basic $auth" -H "Content-type: application/xml" -X DELETE "$server/JSSResource/classes/id/$classID"
done
echo "All classes have been deleted."
# Clean up XML file
rm "$xmlFile"
Posted on 08-22-2024 09:02 AM
this doesnt work