Harun's Microsoft Blog

Archive for September, 2009

HOW TO USE LDIFDE to export and to import directory objects

by on Sep.11, 2009, under Active Directory

This is a step-by-step guide to import and export Organizational Units (OUs) and user accounts from one Active Directory to another. For this example, “SourceDomain” is the name of the domain from which objects are exported and “TargetDomain” is the name of the domain in which objects are imported. LDIFDE can also be used to import most third-party folders to Active Directory.

How to Export the organizational units from the source domain

 

Log on as Administrator in the Source Domain. If you log on using an account that does not have administrative privileges, you may not be able to perform export and import operations against the Active Directory.

At the command prompt, type:

ldifde -f exportOu.ldf -s DC01 -d “dc=SourceDomain,dc=se” -p subtree -r “(objectCategory=organizationalUnit)” -l “cn,objectclass,ou”

NOTE:

DC01 is the Server name of the Source Domain Controller

This command exports all OUs except domain controllers into a file named ExportOU.ldf.

How to Export the user accounts from the source domain

 

At the command prompt, type:

ldifde -f Exportuser.ldf -s DC01 -d “dc=SourceDomain,dc=se” -p subtree -r “(&(objectCategory=person)(objectClass=User)(givenname=*))” -l “cn,givenName,objectclass,samAccountName”

NOTE:

DC01 is the Server name of the Source  Domain Controller

This command exports all users in the Source Domain into a file named Exportuser.ldf. If you do not have all the required attributes, the import operation does not work. The attributes objectclass and samAccountName are required, but more can be added as needed.

INFO: Built-in accounts, such as Administrator, do not have a given name. By default, the LDAP filter used above does not export those accounts. LDIFDE does not support exporting passwords.

INFO: When you omit the -s parameter, LDIFDE chooses a global catalog for exports. Depending on the domain controller placement, this server might be a domain controller for a different domain, and exports might fail. You see this when you examine the output of LDIFDE. In this case, specify a local domain controller of the domain in which the objects are hosted.

Import the organizational units from SourceDomain to TargetDomain

 

Log on as an Administrator in the TargetDomain domain. If you log on using an account that does not have administrative privileges, you may not be able to perform export and import operations against the Active Directory.

Open the file Exportou.ldf using Notepad.

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

NOTE:

DC02 is the Server name of the Target Domain Controller

You should see a message stating the number of entries that have been modified and that the command completed successfully.

INFO: In this situation, you must complete the first step prior to completing the second step so that the OUs are available to contain the users.

How to Import the users from SourceDomain to TargetDomain

 

Open the file Exportuser.ldf using Notepad.

In notepad, open the Edit menu and click Replace.

INFO: Remember that in this example, “SourceDomain” is the name of the domain from which objects are exported and “TargetDomain” is the name of the domain to which objects are imported. You will replace “SourceDomain” with the name of the domain you exported from and you will have to replace “TargetDomain” with the domain you are importing to.

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 Exportuser.ldf -s  DC02  

NOTE: DC02 is the Server name of the Target Domain Controller

View the newly created contacts using either the Active Directory Users and Computers snap-in tool or using the Windows Address Book.

 

INFO:

: Because LDIFDE does not export passwords, when the users are imported into the directory, the account is disabled and the password is set to null. This is done for security reasons. Also, the account option “User must change password at next logon” is selected.

How to Export objects from an entire forest

 

If you need to export OUs, users, and groups from an entire forest, you may either run the above LDIFDE export commands against each domain in the forest, or alternatively, run the query once against the global catalog (GC). To do this, ensure that the domain controller that is specified by the -s switch is a GC, and additionally, specify the GC port using the -t switch. The GC port number is 3268.

For example, to perform the export operation outlined against a GC, the LDIFDE command would be:

ldifde -f Exportuser.ldf -s DC01 -t 3268 -d “dc=SourceDomain,dc=se” -p subtree -r “(&(objectCategory=person)(objectClass=User)(givenname=*))” -l “cn,givenName,objectclass,sAMAccountName”

 

 

NOTE:

DC01 is the Server name of the Source Domain Controller

INFO:

To Modify attributes in AD it is very important that the following format be followed for the import file, especially the “-” on a single line followed by a completely blank line on the next line. To import this file all you need to do is run: ldifde -i -f Import.ldf -s Server.

Sample Import/Modify File Format:

dn: CN=Jane Doe,OU=UserAccounts,DC=harun,DC=se

changetype: modify

replace: extensionAttribute1

extensionAttribute1: Staff

dn: CN=John Doe,OU=UserAccounts,DC=harun,DC=se

changetype: modify

replace: extensionAttribute1

extensionAttribute1: Staff

 

How to Import multivalued attributes

 

Import files with multivalued attributes have the form of:
dn: distinguishedName
changetype: modify
replace: attribute
modify replace: attribute [this is the attribute to be changed]
attribute: value1
attribute: value2
attribute: valueN [where N is the next value] – [hyphen, required to terminate input file]
example:
dn: CN=Connector for Lotus Notes (EX1),CN=Connections,CN=First Routing Group,CN=Routing Groups,CN=First Administrative Group,CN=Administrative Groups,CN=HARUN,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=harun,DC=se changetype: modify replace: msExchExportContainersLinked msExchExportContainersLinked: OU=GroupWise Users,DC=harun,DC=se msExchExportContainersLinked: OU=AD Users,DC=harun,DC=se msExchExportContainersLinked: CN=Users,DC=harun,DC=se

LDIFDE Parameters
-i              Turn on Import Mode (The default is Export)
-f filename     Input or Output filename
-s servername   The server to bind to
-c FromDN ToDN  Replace occurrences of FromDN to ToDN
-v              Turn on Verbose Mode
-j              Log File Location
-t              Port Number (default = 389)
-?              Help
    
Export Parameters
-d RootDN       The root of the LDAP search (Default to Naming Context)
-r Filter       LDAP search filter (Default to “(objectClass=*)”)
-p SearchScope  Search Scope (Base/OneLevel/Subtree)
-l list         List of attributes (comma separated) to look for in an LDAP
                search.
-o list         List of attributes (comma separated) to omit from input
-g              Disable Paged Search
-m              Enable the SAM logic on export
-n              Do not export binary values
    
Import Parameter
-k      The import will go on ignoring ‘Constraint Violation’ and ‘Object
        Already Exists’ errors
    
Credentials Parameters

-a      Sets the command to run using the supplied user distinguished name
        and password. For example: “cn=yourname,dc=yourcompany,dc-com
        password” 
-b      Sets the command to run as username domain password. The default is
        to run using the
credentials of the currently logged on user.

Comments Off on HOW TO USE LDIFDE to export and to import directory objects more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...