How to Export and Import OU's and Users in Active Directory with Multi-valued
Sometimes you need to export ou's and Users from one domain to different domain or same domain for testing purpose or for User's requirements. Exporting users and Ou's are bit easy than importing them, because sometimes importing ou's or especially Users gets error and believe me it will give you many type of errors. I am writing the secure way to import and export Users's and Ous from one Directory to another with different domain name or Same Name.
You will find many types of commands on internet right now that will export your ou's and Users but many of them give you error because of invalid command or Script, About all of commands will export single valued users means export the users without Display Name, Tel no,City, and other attributes which will be compulsory for you in the importing time
So, i am writing the all compulsory steps that will be used in exporting and Importing AD Users and OU's
Log on as Administrator in the Source Domain (From where you want to export Directory Users and OU's).You must have Administrator Privileges otherwise you will be be able to perform this task, So first of all you have to export OU's them Users.Please follow the Steps. NOTE: This will export and import Users with Single Valued
1- Please Open PowerShell run as Administrator and Paste the following command for exporting all OUs
2- ** ldifde -f c:\exportOu.ldf -s MYSP -d “dc=SPSERVER,dc=COM” -p subtree -r “(objectCategory=organizationalUnit)” -l “cn,objectclass,ou”**
3- Where MYSP is my Server Name so change this and SPSERVER.COM is my Domain name so kindly replace this by your Server name and Domain
4- In Notepad, on the Edit menu, click Replace.
In the Find what box type, SourceDomain. In the Replace with box type, TargetDomain.Click Replace All.After you verify that the domain names are replaced, save, and then close the file.
At the command prompt, type:
ldifde -i -f ExportOU.ldf -s DC02
5- Then Paste the following command for exporting all the users in domain except the default one
6- ldifde -f c:\Exportuser.ldf -s MYSP -d “dc=SPSERVER,dc=COM” -p subtree -r “(&(objectCategory=person)(objectClass=User)(givenname=*))” -l “cn,givenName,objectclass,samAccountName”
7- Same as previous Case kindly replace your **Domain **and Server Name. For Importing Same as we did in OU's. Open the exportuser.ldf as Notepad and replace all the source domain to target domain and then paste the below script on command prompt
**ldifde -i -f Exportuser.ldf -s DC02 **
*** In Single valued attributes the Passwords will not be exported so you have to do it manually
For the Multi-Valued Users follow the following Steps
1- Please Open Command Prompt run as Administrator and Paste the following command for exporting all Users
2- ldifde -f C:\Exportmyusers.ldf -s MyExchange -t 3268 -d “dc=EXSERVER,dc=com” -p subtree -r “(&(objectCategory=person)(objectClass=User)(givenname=*))”-l “cn,displayName,objectclass,sAMAccountName,userPrincipalName,department,mobile,streetAddress,title,st,l,co,company,physicalDeliveryOfficeName"
3- Where **MyExchange **is my Server Name so change this and EXSERVER.COM is my Domain name so kindly replace this by your Server name and Domain
4- You just have to export the **Users **only for **OU **follow the above steps, this will export the all Users of your AD included **Multivalued Attributes **
For importing Multivalued follow steps
5- For Importing Same as we did in previously. Open the exportuser.ldf as Notepad and replace all the source domain to target domain and then paste the below script on command prompt
**ldifde -i -f Exportuser.ldf -s DC02 **
** You don't have to import all the user's attribute more than i wrote in Multivalued section for more detail please visit Microsoft Official blog