Skip to content

Instantly share code, notes, and snippets.

Last active May 17, 2023 12:22
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save talkingmoose/d8dbdbc920cbaddd7d60f44f17bf268a to your computer and use it in GitHub Desktop.
Use Jamf Pro Classic API to send EraseDevice command (Erase All Content and Settings on macOS Monterey and newer) to one or multiple computers by Jamf Pro ID. This script doesn't support computers locked using Device Lock with unique passcodes.
Written by:William Smith
Partner Program Manager
Originally posted: November 9, 2022
Purpose: Send the EraseDevice MDM command to one or multiple computers
through the Jamf Pro Classic API.
1. Provide the information below for jamfProURL, username, password,
computerIDs and passcode.
2. Run the script using a code/text editor such as BBEdit or Coderunner.
Or save the script to your desktop and use Terminal to run the script.
Except where otherwise noted, this work is licensed under
"Experience is simply the name we give our mistakes."
— Oscar Wilde
# server and credential information
# computer IDs separated by commands (e.g. "1" or "1,2,4,12")
# request auth token
authToken=$( /usr/bin/curl \
--request POST \
--silent \
--url "$jamfProURL/api/v1/auth/token" \
--user "$username:$password" )
echo "$authToken"
# parse auth token
token=$( /usr/bin/plutil \
-extract token raw - <<< "$authToken" )
echo Token: "$token"
# send data to Jamf Pro Classic API with command to EraseDevice
response=$( /usr/bin/curl \
--header "Authorization: Bearer $token" \
--header "Content-Type: text/xml" \
--request POST \
--silent \
--url "$jamfProURL/JSSResource/computercommands/command/EraseDevice/passcode/$passcode/id/$computerIDs" )
echo "$response"
# expire auth token
/usr/bin/curl \
--header "Authorization: Bearer $token" \
--request POST \
--silent \
--url "$jamfProURL/api/v1/auth/invalidate-token"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment