Home > Jamf Pro, Jamf Pro API, Scripting > Removing the Restart Options section from Jamf Pro policies using the API

Removing the Restart Options section from Jamf Pro policies using the API

As part of setting up new Jamf Pro policies, the Restart Options section is automatically added to newly-created policies.

Screen Shot 2020 05 14 at 5 41 49 PM

For policies which don’t need it though, this section should be removed as a best practice to avoid accidental triggering of a restart where one isn’t needed or wanted. In some cases, the options provided by this section are never needed and it may be useful to be able to remove the Restart Options section from 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><reboot><no_user_logged_in>Do not restart</no_user_logged_in><user_logged_in>Do not restart</user_logged_in></reboot></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 remove the restart options from 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><reboot><no_user_logged_in>Do not restart</no_user_logged_in><user_logged_in>Do not restart</user_logged_in></reboot></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 script to assist with these tasks. This script is designed to use the Jamf Pro API to do the following:

  • Identify the individual IDs of all computer policies stored on a Jamf Pro server
  • Remove the restart options of the individual policies using their policy ID
  • Display HTTP return code and API output

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

Screen Shot 2020 05 14 at 5 19 37 PM

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 script to exit.

Screen Shot 2020 05 14 at 5 21 43 PM

If the script is successful, you should see output like this for each policy.

Removing restart options from 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

The script is available from following address on GitHub:

https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/Casper_Scripts/Jamf-Pro-Remove-Restart-Options-From-All-Policies

  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: