Mirror an OU Structure to a Test Domain

A while back I wrote a couple of scripts for backing up Group Policies and then importing that backup into a test environment. More on those scripts here:

Comprehensive GPO Backup / Import Scripts

 

Notice the use of 'comprehensive' in the script titles. I chose this word because there were a couple of things the scripts didn't do. One of those things was to mirror the OU structure of the source domain to the target domain. This is no longer an issue...

Let me introduce a couple of companion scripts to ensure we have a matching OU structure in the test environment:

Dump AD OU Structure Script

Mirror AD OU Structure Script

 

The names give the script functions away:

  • the first script dumps the OU name, OU DN, OU parent DN and domain DN to an XML file
  • the second script reconstructs the OU structure in a target test domain

 

No OUs were hurt in the production of this post...