Export/Import Users/Groups from AD to Test AD

%3CLINGO-SUB%20id%3D%22lingo-sub-2336724%22%20slang%3D%22en-US%22%3EExport%2FImport%20Users%2FGroups%20from%20AD%20to%20Test%20AD%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2336724%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20trying%20to%20compile%20a%20script%20that%20will%20help%20in%20my%20project.%3C%2FP%3E%3CP%3EProject%20scope%3A%26nbsp%3B%20Mirror%20Prod%20to%20Dev%20AD.%26nbsp%3B%20Export%20all%20users%20and%20security%20group%20membership%20(including%20nested%20groups)%20to%20a%20csv.%26nbsp%3B%20Users%20live%20in%20Sub%20OU's%20and%20sub%20OU's%20of%20the%20previous%20OU%20so%20would%20need%20to%20capture%20all.%26nbsp%3B%20My%20current%20script%20you%20have%20to%20manually%20change%20each%20OU%20when%20running%20and%20this%20is%20not%20doable%20long%20term.%3C%2FP%3E%3CP%3EI%20need%20to%20incorporate%20the%20correct%20attributes%20needed%20to%20build%20a%20new%20AD%20account%20on%20import%20(FirstName%2C%20email%20address%2C%20UPN%2C%20etc.)%3C%2FP%3E%3CP%3EAfter%20the%20export%2C%20I%20can%20massage%20the%20csv%20to%20use%20the%20new%20test%20domain%20information%20so%20the%20import%20process%20will%20work%20correctly.%26nbsp%3B%20Import%20process%20should%20build%20new%20users%2C%20assign%20temp%20password%20and%20also%20overlook%20any%20users%20that%20are%20already%20built%20in%20the%20new%20test%20AD.%26nbsp%3B%20I%20did%20get%20some%20users%20there%20and%20need%20the%20script%20to%20overlook%20ones%20that%20may%20already%20exists%20but%20still%20add%20them%20to%20the%20right%20group%20memberships.%3C%2FP%3E%3CP%3EAD%20server%20is%202016Datacenter%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20help%20is%20truly%20appreciated!%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2336724%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%20-%20AD%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2337655%22%20slang%3D%22en-US%22%3ERe%3A%20Export%2FImport%20Users%2FGroups%20from%20AD%20to%20Test%20AD%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2337655%22%20slang%3D%22en-US%22%3EHi%2C%3CBR%20%2F%3EI%20dont%20think%20you%20need%20PowerShell%20more%20than%20restore%20a%20backup%20of%20your%20AD.%3CBR%20%2F%3EI%20would%20recommend%20to%20create%20a%20mother%20ISOLATED%20environment%20and%20restore%20your%20Active%20Directory%20to%20this%20environment%20and%20do%20your%20test%20in%20the%20way%20you%20want.%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2342709%22%20slang%3D%22en-US%22%3ERe%3A%20Export%2FImport%20Users%2FGroups%20from%20AD%20to%20Test%20AD%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2342709%22%20slang%3D%22en-US%22%3EThat%20sounds%20like%20an%20idea%20however%2C%20this%20AD%20needs%20to%20reach%20the%20internet%2C%20communicate%20with%20SSO%20and%20Office365.%20I%20feel%20that%20would%20create%20a%20conflict%20if%20so.%20I%20worked%20a%20bit%20with%20PS%20but%20just%20unable%20to%20come%20up%20with%20a%20script%20that%20will%20complete%20this%20task.%3C%2FLINGO-BODY%3E
New Contributor

I'm trying to compile a script that will help in my project.

Project scope:  Mirror Prod to Dev AD.  Export all users and security group membership (including nested groups) to a csv.  Users live in Sub OU's and sub OU's of the previous OU so would need to capture all.  My current script you have to manually change each OU when running and this is not doable long term.

I need to incorporate the correct attributes needed to build a new AD account on import (FirstName, email address, UPN, etc.)

After the export, I can massage the csv to use the new test domain information so the import process will work correctly.  Import process should build new users, assign temp password and also overlook any users that are already built in the new test AD.  I did get some users there and need the script to overlook ones that may already exists but still add them to the right group memberships.

AD server is 2016Datacenter

 

Any help is truly appreciated!  

 

4 Replies
Hi,
I dont think you need PowerShell more than restore a backup of your AD.
I would recommend to create a mother ISOLATED environment and restore your Active Directory to this environment and do your test in the way you want.
That sounds like an idea however, this AD needs to reach the internet, communicate with SSO and Office365. I feel that would create a conflict if so. I worked a bit with PS but just unable to come up with a script that will complete this task.

@Thedarkpools 

 

restoring domain controllers and other critical servers into a segregated environment is normally the best method - as recreating the server / users is not a true representation of the production domain, and would potentially lead to non predictable results - things like SIDs etc will be different and the potential for configuring differences between Prod and Test is greater.

 

As for requiring access to SSO and Office365 if you are using the same namespace/forest/domain/upn trying to connect to the same tenant you will run into issues regardless of the approach (PowerShell verses cloned/restored). Typically we would have the test domain going into a test tenant...

if forest/domain namespaces are different then you could connect both domains into the same tenant - with AD Connect in Production network connecting to the test network (Two different domains in one Office 365 tenant - Microsoft Tech Community) for more information. But again if your user details UPNs etc are the same you will run into issues and potentially have your production users soft-matched to the test domain user account 

That makes sense and I hear what you are saying. This is a test Office tenant, and test AD, the only thing that is the same is the username, and security groups, albeit going from john.doe@mycompany.com to john.doe@testcompany.com I just simply want to match the user and security groups. So far, what I have tested does work but this is only a few OU's and a few Users. I didn't think this would be that difficult to obtain as seems there are tons of PS commands to make this happen, but I just am stuck on OU specific and not the full AD structure.
Would it make it easier to paste what script I have and then try to see if someone can modify?