Posted on 08-11-2017 12:56 PM
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.
Posted on 08-14-2017 01:18 PM
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
Posted on 08-17-2017 06:09 AM
Thank you.
Will give it a try.
Posted on 08-24-2017 08:08 AM
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.