How We Worklet: Python Script to Migrate Policies from Org to Org

In this video, IT Cloud Engineer Ryan Braunstein shares a Python script that has assisted in a migration between two orgs within the Automox product. We have a hunch you may find your own use for it!

This script would be useful for MSPs that absorbed the IT responsibilities of other companies that may already utilize our Automox product or even larger-scale organizations that are looking to consolidate Automox orgs in acquisitions, mergers, or things of that nature. Moving policies one by one could take hours, so feel free to utilize this script to automate that process and save some time!

Video Transcript:

Hi everyone. My name is Ryan Braunstein and I am an IT Cloud Engineer here at Automox.

Today I want to talk to you about a script I wrote that assisted us in the migration between two of our orgs within our product. The script would be extremely useful for MSPs that absorbed the IT responsibilities of other companies that may already utilize our Automox product um or even larger-scale organizations that are looking to consolidate Automox orgs in acquisitions or mergers, or things of that nature.

Our IT team was looking to migrate all of our devices into a separate org that would enable us to test certain features across our internal devices and we found that our only toolset to migrate these policies was written in PowerShell.

While we could have spun up a Windows box and used the script to accomplish our task, we decided to create something that would be more universal to anyone's toolkit and since Python is a widely utilized coding language, I ended up opting for that.

So on the lefthand side of the screen here, you see, our original org and this is like our old, you know, deprioritized organization. We have so many policies here, we have 64. Moving these by hand would take hours on end. Our PowerShell script requires us to spin up a box to deploy it in and set up, you know, the whole environment.

So over here on the right is the new org that I just spun up for the sake of this video. One of the biggest things you're gonna need from both orgs is a working API token, which you can generate under Keys and I'm gonna show this one, it's a demo so it's not a big deal.

And so I've created a little um key here and this will actually help just deploy this through this script. Now over here, this is the full script I've written. You don't have to have your header values set up in this manner. This is just how I did it for the sake of the script so that I could set up our API token in a, you know, environment variable throughout the script. It goes down here. It starts off retrieving all policy ID numbers within the current org and it adds them to a list.

It then passes that list into the next function here and it queries each one of those policy IDs and pulls information about them. After that, it goes down to this area and formats everything the way it needs to be to pass it into the new org. And I see I've missed a new org guide down here already and it posts it and then passes it through to the next order.

So I'm just gonna run this really quick and it should run correctly. Just gonna go ahead and double-check, let's see what happens here.

There we go. 201 is the successful response from it. You'll get a couple of four hundreds if there's already a policy in there that matches one from the original org and I'm sure I could probably refresh on this page right now and it would show some of the policies coming in, yep, so it's already starting to pass some of these policies through to the new org. The most important part of this is that it will not move the payloads over to the new org. So that's something you will still have to do manually but it does save you a lot of time in terms of, you know copy and pasting whatever evaluation code you have copy and pasting, you know, whatever scripts you may have in here and it does the, you know, status and the functionality of it 1-1.

So all of these variables here will be passed across as well. It does not assign them to the
groups when it comes over. So that is something you will have to do and there are probably amendments that can be made in this code that could make it run a little smoother.

This was something I spun up on the fly and accomplished in a shorter amount of time than it would have taken me to move everything over. With that being said, I hope this helps in any kind of consolidation or migrations that you do when utilizing Autumox. Thank you