Add Limitation All Policies

veal13
New Contributor

Hello Jamf Nation,
We have to add a network segment limitation to all policies.
Instead of adding one by one, is there a way to do this via mysql.

Thanks for any advice in advance.

3 REPLIES 3

bburdeaux
Contributor II

While this can be done in mysql, I'd strongly recommend doing it in the API.

To do it in the API, you'll need to find the ID of the network segment, and create a .csv list containing the IDs of every policy you need to change. Getting the IDs for every policy is most easily accomplished in mysql, with the query "select policy_id, name from policies;" and making the .csv from that. I'd recommend leaving the names attached as deleted policies tend to stick around in the database. Once you have the list, you can use something like the script below to add the limitation.

#!/bin/sh

TARGET = /Path/to/list.csv
SEGMENT = Network Segment ID

cat $TARGET | while read POLICY; do
curl -sk -u username:password -H "Content-Type: text/xml" -d "<?xml version="1.0" encoding="ISO-8859-1"?><policy><scope><limitations><network_segments><network_segment><id>$SEGMENT</id><network_segment></network_segments></limitation></scope></policy>" https://your.jss.url:8443/JSSResource/policies/id/$POLICY -X PUT
done

veal13
New Contributor

Thank you.
Will give it a try.

veal13
New Contributor

This is working for us.
But a question, when there are exclusions associated with a policy. The command to add the limitations, adds the limitation, but removes the existing exclusions.
Is there an edit that can leave any existing exclusions in tact..

The advice is much appreciated.