Any way to bulk move policies to a site?

stevehahn
Contributor

I've created a new Site where a bunch of Macs and their associated policies will be moved... I know how to bulk move the Macs into the new site, but it doesn't look like there's a way to do the same with policies. Will I have to move them one by one or is there a way to do it in bulk (perhaps through the API)?

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

Hmm. It may be possible to recreate the policies using the API, but its outside of the realm of things I've personally attempted, so not so sure.
I don't know if there's any batch related functions around moving things from one site to another. I don't think so.

Actually, in thinking about it, it might be possible to simply change the site information for each policy, but, as I do not use Sites at all, I don't have a good reference to test with. For example, every policy has a section in its xml that looks like this:

<site>
      <id>-1</id>
      <name>None</name>
</site>

The -1 and corresponding None indicates its not in any Site (global policy), but I'm wondering if simply changing that one value in the JSS (and the name string?) would be enough to move the policy into the Site designated by the ID and name? Anyone know for sure on that?

View solution in original post

3 REPLIES 3

mm2270
Legendary Contributor III

Hmm. It may be possible to recreate the policies using the API, but its outside of the realm of things I've personally attempted, so not so sure.
I don't know if there's any batch related functions around moving things from one site to another. I don't think so.

Actually, in thinking about it, it might be possible to simply change the site information for each policy, but, as I do not use Sites at all, I don't have a good reference to test with. For example, every policy has a section in its xml that looks like this:

<site>
      <id>-1</id>
      <name>None</name>
</site>

The -1 and corresponding None indicates its not in any Site (global policy), but I'm wondering if simply changing that one value in the JSS (and the name string?) would be enough to move the policy into the Site designated by the ID and name? Anyone know for sure on that?

stevehahn
Contributor

Thanks @mm2270, it looks like you are correct--as a test, I created an xml file with the site info I wanted to add to the policies:

<policy>
  <general>
    <site>
      <id>[site ID]</id>
      <name>[site name]</name>
    </site>
  </general>
</policy>

Then put together a simple script to change the info on a throwaway policy I created:

#/bin/bash

apiUsername="<user>"
apiPassword="<password>"
xmlFile="/path/to/xml/file"
jssServer="https://<your-jss-url>:8443"
policyID="<policy ID>"

curl -s -k -u "${apiUsername}:${apiPassword}" -H "Content-Type: application/xml" -X "PUT" -d "@${xmlFile}" "${jssServer}/JSSResource/policies/id/${policyID}"

From there it should be fairly simple to dump a list of the policies I need to update and run this against each of those--thanks for the assist!

designbridge
New Contributor II

You can always use JSS Migration utility https://github.com/igeekjsc/JSSAPIscripts