Home > Jamf Pro, Jamf Pro API, Scripting > Enabling or disabling all Jamf Pro policies using the API

Enabling or disabling all Jamf Pro policies using the API

Every so often, it may be useful to be able to enable or disable all of your current Jamf Pro policies. In those cases, depending on how many policies you have, it can be tedious to have to do them one at a time using the admin console.

However, with the right API calls in a script, it’s straightforward to perform these tasks using the Jamf Pro API. For more information, please see below the jump.

To disable a Jamf Pro policy, you can use curl to send an API call similar to the one shown below:


curl -H "Content-Type: application/xml" -X PUT -d '<policy><general><enabled>false</enabled></general></policy>' https://jamfpro.server.here/JSSResource/policies/id/policy_id_here –user jamfpro_user_here:jamfpro_password_here

view raw

gistfile1.txt

hosted with ❤ by GitHub

As an example, here’s how the API call would look if using the following information to disable a specified Jamf Pro policy:

  • Jamf Pro server: https://jamfpro.demo.com
  • Jamf Pro username: jpadmin
  • Jamf Pro username’s password: Password1234
  • Jamf Pro policy ID number: 27


curl -H "Content-Type: application/xml" -X PUT -d '<policy><general><enabled>false</enabled></general></policy>' https://jamfpro.demo.com/JSSResource/policies/id/27 –user jpadmin:Password1234

view raw

gistfile1.txt

hosted with ❤ by GitHub

To enable a Jamf Pro policy, you can use curl to send an API call similar to the one shown below:


curl -H "Content-Type: application/xml" -X PUT -d '<policy><general><enabled>true</enabled></general></policy>' https://jamfpro.server.here/JSSResource/policies/id/policy_id_here –user jamfpro_user_here:jamfpro_password_here

view raw

gistfile1.txt

hosted with ❤ by GitHub

If using the same information as the example above, here’s how the API call would look when enabling the specified Jamf Pro policy


curl -H "Content-Type: application/xml" -X PUT -d '<policy><general><enabled>true</enabled></general></policy>' https://jamfpro.demo.com/JSSResource/policies/id/27 –user jpadmin:Password1234

view raw

gistfile1.txt

hosted with ❤ by GitHub

Since running the API calls individually may get tedious, I’ve written a couple of scripts to assist with these tasks:

  • Jamf-Pro-Disable-All-Policies.sh
  • Jamf-Pro-Enable-All-Policies.sh

These scripts are designed to use the Jamf Pro API to do the following:

  • Identify the individual IDs of the computer policies stored on a Jamf Pro server
    • If running Jamf-Pro-Disable-All-Policies.sh, disable the policy using its policy ID
    • If running Jamf-Pro-Enable-All-Policies.sh, enable the policy using its policy ID
  • Display HTTP return code and API output

When the script is run, you should see output similar to that shown below. Because these scripts affect all policies on the Jamf Pro server, the scripts will ask you to confirm that you want to do this by typing the following when prompted:

YES

Any other input will cause the scripts to exit.

Screen Shot 2019 12 16 at 3 23 32 PM

If the script is successful, you should see output like this for each policy. In this case, this is output from Jamf-Pro-Disable-All-Policies.sh:


Disabling policy ID number 1.
201 <?xml version="1.0" encoding="UTF-8"?><policy><id>1</id></policy>

view raw

gistfile1.txt

hosted with ❤ by GitHub

Screen Shot 2019 12 16 at 3 24 19 PM

 

The policy enabling and disabling scripts are available from following addresses on GitHub:

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

Leave a comment