Home > Jamf Pro, Jamf Pro API, Scripting > Deleting all Jamf Pro policies in a specified category

Deleting all Jamf Pro policies in a specified category

Every so often, I need to delete a bunch of Jamf Pro policies at once. One convenient way I’ve found to do this is to assign all the policies I want to delete to one category which doesn’t have any other policies assigned to it. Once assigned, I can then use the API to delete them all at once.

To assist with this task, I’ve been using a script written by Jeffrey Compton but over time I found that I wanted more functionality. To meet my own needs, I took Jeffery’s original idea and written my own script to target the policies in a particular Jamf Pro category. For more details, please see below the jump.

This script is designed to do the following:

  1. List all categories on a Jamf Pro server.
  2. Allow a category to be specified.
  3. List all policies (if any) associated with that category.
  4. Confirm that all policies in that category should be deleted.
  5. Delete all policies in that category.

For authentication, the script can accept hard-coded values in the script, manual input or values stored in a ~/Library/Preferences/com.github.jamfpro-info.plist file.

The plist file can be created by running the following commands and substituting your own values where appropriate:

To store the Jamf Pro URL in the plist file:

defaults write com.github.jamfpro-info jamfpro_url https://jamf.pro.server.goes.here:port_number_goes_here

To store the account username in the plist file:

defaults write com.github.jamfpro-info jamfpro_user account_username_goes_here

To store the account password in the plist file:

defaults write com.github.jamfpro-info jamfpro_password account_password_goes_here

When the script is run, you should see output similar to that shown below.

You’ll be requested to enter the name of a category.

Screen Shot 2020 06 08 at 3 10 47 PM

 

You’ll be asked to confirm that you want to delete the relevant policies.

Screen Shot 2020 06 08 at 3 11 46 PM

 

Once confirmed, the policies will be deleted.

Screen Shot 2020 06 08 at 3 12 42 PM

The script is available from following address on GitHub:

https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/Casper_Scripts/Jamf-Pro-Delete-All-Policies-In-Specified-Category

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: