Home > Jamf Pro, Jamf Pro API, Scripting > Using the Jamf Pro API to delete computers from Jamf Pro
Every so often, I need to delete one or multiple computers from a Jamf Pro server. This can be accomplished in the Jamf Pro admin console, but it can also be accomplished via the Jamf Pro API’s computers-inventory API endpoint. For more details, please see below the jump.
The API command to delete a computer inventory record from a Jamf Pro server should look similar to this:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I was able to use the API information discussed above to create a script which:
The script is named Delete_Computers_From_Jamf_Pro.sh and is available via the link below:
The script is designed to take in a set of Jamf Pro ID numbers in a plaintext file, where the Jamf Pro ID numbers correspond the Macs you want to delete. The script can also accept one Jamf Pro ID number as input, if a plaintext file containing Jamf Pro ID numbers is not available.
Three items are required to use these scripts:
Jamf Pro account privileges required by the Jamf Pro server account referenced above:
Jamf Pro Server Objects:
If you want to delete multiple computers at once from Jamf Pro, you will also need to provide a plaintext file containing the Jamf Pro IDs of the computer you wish to delete. The plaintext file should look similar to this:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 416462 | |
| 842736 | |
| 434703 | |
| 338517 | |
| 481915 | |
| 596669 |
Once the specified items are available, the scripts can be run using the following commands:
To use Delete_Computers_From_Jamf_Pro.sh to delete one computer:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /path/to/Delete_Computers_From_Jamf_Pro.sh |
To use Delete_Computers_From_Jamf_Pro.sh to delete multiple computers:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /path/to/Delete_Computers_From_Jamf_Pro.sh /path/to/plaintext_filename_here.txt |
When using Delete_Computers_From_Jamf_Pro.sh to delete one computer, you should see output that looks like this:
As part of the script’s run, a report will be generated and you’ll be notified of where it is stored. The report will be in TSV format and appear similar to what’s shown below:
When using Delete_Computers_From_Jamf_Pro.sh to delete multiple computers, you should see output that looks like this:
The corresponding report will appear similar to what’s shown below:
In addition to the scripts described above which use user accounts for authentication, there are also matching scripts which use API client authentication available on GitHub via the links above. If setting up an API client with limited rights, here are the required API role privileges for the API client on the Jamf Pro server: