Skip to main content
Question

Jamf API Help

  • May 26, 2021
  • 1 reply
  • 0 views

KyleEricson
Forum|alt.badge.img+16

I need a script to edit all policies in Jamf to exclude 1 computer group. I have a script to edit one policy, but I need to get all policies and exclude 1 smart group.

#!/bin/sh
apiUsername="username"
apiPassword="password"
jssURL="jss.url.here"
​
policyID=2018
​
curl -sS -k -u $apiUsername:$apiPassword https://$jssURL:8443/JSSResource/policies/id/$policyID -H "Content-Type: application/xml" -d "<policy><scope><exclusions><computer_groups><computer_group><id>1</id><name>All Managed Clients</name></computer_group></computer_groups></exclusions></scope></policy>" -X PUT

1 reply

Mauricio11
Forum|alt.badge.img+11
  • Valued Contributor
  • 173 replies
  • May 28, 2021

@KyleEricson If you are looking for a "one-off" it would be simpler/faster to get a list of policy IDs that you would like to target.
An example:

#!/bin/bash

# JAMF details
jamfServerAddress=''
jamfAdminName=''
jamfAdminPassword=''

# policy list [i.e. (2018 2019 238 878)]
policyIDs=(   )

uploadPolicy() {
  policyID="$1"
  policyData="<policy><scope><exclusions><computer_groups><computer_group><id>1</id><name>All Managed Clients</name></computer_group></computer_groups></exclusions></scope></policy>"
  putOut=$(/usr/bin/curl --write-out '%{http_code}' --output /dev/null --silent "$jamfServerAddress/policies/id/$policyID" --user "$jamfAdminName:$jamfAdminPassword" --header "Content-Type: text/xml" --request PUT  -d "$policyData")
  if [ $putOut -eq 201 ]; then
    echo "SUCCESS"
  else
    echo "FAIL ($putOut)"
  fi
}

for thisPolicy in "${policyIDs[@]}"
do
    echo "Processing policy ID: $thisPolicy"
    uploadPolicy $thisPolicy
done

I hope this helps.
Regards
Mauricio


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings