Jamf API Help

KyleEricson
Valued Contributor II

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
Read My Blog: https://www.ericsontech.com
1 REPLY 1

Mauricio
Contributor III

@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