{"id":77,"date":"2009-09-11T01:50:31","date_gmt":"2009-09-11T00:50:31","guid":{"rendered":"https:\/\/harun.se\/blog\/?p=77"},"modified":"2009-09-11T02:01:47","modified_gmt":"2009-09-11T01:01:47","slug":"how-to-use-ldifde-to-export-and-to-import-directory-objects","status":"publish","type":"post","link":"https:\/\/harun.se\/blog\/?p=77","title":{"rendered":"HOW TO USE LDIFDE to export and to import directory objects"},"content":{"rendered":"<p><strong><\/strong><span style=\"color: #ffffff;\">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, &#8220;SourceDomain&#8221; is the name of the domain from which objects are exported and &#8220;TargetDomain&#8221; 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. <\/span><\/p>\n<div><strong><span style=\"color: #ffffff;\">How to Export the organizational units from the source domain<\/span><\/strong><\/div>\n<p><strong>\u00a0<\/p>\n<p><\/strong><\/p>\n<p><span style=\"color: #ffffff;\">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. <\/span><\/p>\n<p><span style=\"color: #ffffff;\">At the command prompt, type: <\/span><\/p>\n<p><span style=\"color: #ff0000;\">ldifde -f exportOu.ldf -s <em>DC01<\/em> -d &#8220;dc=SourceDomain,dc=se&#8221; -p subtree -r &#8220;(objectCategory=organizationalUnit)&#8221; -l &#8220;cn,objectclass,ou&#8221; <\/span><\/p>\n<div><strong><span style=\"color: #ffffff;\">NOTE: <\/span><\/strong><\/div>\n<p><strong><span style=\"color: #ffffff;\">DC01 is the Server name of the\u00a0Source Domain Controller<\/span><\/p>\n<p><\/strong><\/p>\n<p><span style=\"color: #ffffff;\">This command exports all OUs except domain controllers into a file named ExportOU.ldf. <\/span><\/p>\n<div><strong><span style=\"color: #ffffff;\">How to Export the user accounts from the source domain<\/span><\/strong><\/div>\n<p><strong>\u00a0<\/p>\n<p><\/strong><\/p>\n<p><span style=\"color: #ffffff;\">At the command prompt, type: <\/span><\/p>\n<p><span style=\"color: #c0c0c0;\"><span style=\"color: #ff0000;\">ldifde -f Exportuser.ldf -s <em>DC01<\/em> -d &#8220;dc=SourceDomain,dc=se&#8221; -p subtree -r &#8220;(&amp;(objectCategory=person)(objectClass=User)(givenname=*))&#8221; -l &#8220;cn,givenName,objectclass,samAccountName&#8221;<\/span> <\/span><\/p>\n<div><strong><span style=\"color: #ffffff;\">NOTE: <\/span><\/strong><\/div>\n<p><strong><span style=\"color: #ffffff;\">DC01 is the Server name of the Source\u00a0 Domain Controller<\/span><\/p>\n<p><\/strong><\/p>\n<div><span style=\"color: #ffffff;\">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 <strong>objectclass<\/strong> and <strong>samAccountName<\/strong> are required, but more can be added as needed.<\/span><\/div>\n<p><span style=\"color: #ffffff;\"><strong>INFO:<\/strong> 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.<\/p>\n<p><strong>INFO:<\/strong> When you omit the <strong>-s<\/strong> 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.<\/p>\n<p><\/span><\/p>\n<div><strong><span style=\"color: #ffffff;\">Import the organizational units from SourceDomain to TargetDomain<\/span><\/strong><\/div>\n<p><strong>\u00a0<\/p>\n<p><\/strong><\/p>\n<p><span style=\"color: #ffffff;\">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. <\/span><\/p>\n<p><span style=\"color: #ffffff;\">Open the file Exportou.ldf using Notepad. <\/span><\/p>\n<p><span style=\"color: #ffffff;\">In Notepad, on the <strong>Edit<\/strong> menu, click <strong>Replace<\/strong>. <\/span><\/p>\n<p><span style=\"color: #ffffff;\">In the Find what box type, SourceDomain. In the Replace with box type, TargetDomain. <\/span><\/p>\n<p><span style=\"color: #ffffff;\">Click Replace All. <\/span><\/p>\n<p><span style=\"color: #ffffff;\">After you verify that the domain names are replaced, save, and then close the file. <\/span><\/p>\n<p><span style=\"color: #ffffff;\">At the command prompt, type: <\/span><\/p>\n<p><span style=\"color: #ff0000;\">ldifde -i -f ExportOU.ldf -s DC02<\/span><\/p>\n<div><em><strong><em><span style=\"color: #ffffff;\">NOTE: <\/span><\/em><\/strong><\/em><\/div>\n<p><em><strong><em><span style=\"color: #ffffff;\">DC02 is the Server name of the Target Domain Controller<\/span><\/p>\n<p><\/em><\/strong><\/p>\n<div><span style=\"color: #ffffff;\">You should see a message stating the number of entries that have been modified and that the command completed successfully.<\/span><\/div>\n<p><\/em><span style=\"color: #ffffff;\"><strong>INFO:<\/strong> 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.<\/p>\n<p><\/span><\/p>\n<div><strong><span style=\"color: #ffffff;\">How to Import the users from SourceDomain to TargetDomain<\/span><\/strong><\/div>\n<p><strong>\u00a0<\/p>\n<p><\/strong><\/p>\n<p><span style=\"color: #ffffff;\">Open the file Exportuser.ldf using Notepad. <\/span><\/p>\n<div><span style=\"color: #ffffff;\">In notepad, open the <strong>Edit<\/strong> menu and click <strong>Replace<\/strong>.<\/span><\/div>\n<p><span style=\"color: #ffffff;\"><strong>INFO:<\/strong> Remember that in this example, &#8220;SourceDomain&#8221; is the name of the domain from which objects are exported and &#8220;TargetDomain&#8221; is the name of the domain to which objects are imported. You will replace &#8220;SourceDomain&#8221; with the name of the domain you exported from and you will have to replace &#8220;TargetDomain&#8221; with the domain you are importing to.<\/p>\n<p><\/span><\/p>\n<p><span style=\"color: #ffffff;\">In the Find what box type, SourceDomain. In the Replace with box, type TargetDomain. <\/span><\/p>\n<p><span style=\"color: #ffffff;\">Click Replace All. <\/span><\/p>\n<p><span style=\"color: #ffffff;\">After you verify that the domain names are replaced, save, and then close the file. <\/span><\/p>\n<p><span style=\"color: #ffffff;\">At the command prompt, type: <\/span><\/p>\n<p><span style=\"color: #ffffff;\"><span style=\"color: #ff0000;\">ldifde -i -f Exportuser.ldf -s\u00a0 DC02\u00a0\u00a0 <\/span><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><em><span style=\"color: #ffffff;\">NOTE:<\/span> DC02 is the Server name of the Target Domain Controller<\/em> <\/span><\/p>\n<p><span style=\"color: #ffffff;\">View the newly created contacts using either the Active Directory Users and Computers snap-in tool or using the Windows Address Book. <\/span><\/p>\n<p>\u00a0<\/p>\n<div><strong><span style=\"color: #ffffff;\">INFO:<\/span><\/strong><\/div>\n<p><strong><span style=\"color: #ffffff;\">: 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 &#8220;User must change password at next logon&#8221; is selected. <\/span><\/p>\n<div><strong><span style=\"color: #ffffff;\">How to Export objects from an entire forest<\/span><\/strong><\/div>\n<p><strong>\u00a0<\/p>\n<p><\/strong><\/strong><\/p>\n<div><span style=\"color: #ffffff;\">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.<\/span><\/div>\n<p><span style=\"color: #ffffff;\">For example, to perform the export operation outlined against a GC, the LDIFDE command would be:<\/p>\n<p><\/span><\/p>\n<p><span style=\"color: #ff0000;\">ldifde -f Exportuser.ldf -s <em>DC01<\/em> -t 3268 -d &#8220;dc=SourceDomain,dc=se&#8221; -p subtree -r &#8220;(&amp;(objectCategory=person)(objectClass=User)(givenname=*))&#8221; -l &#8220;cn,givenName,objectclass,sAMAccountName&#8221; <\/span><\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<div><strong><span style=\"color: #ffffff;\">NOTE: <\/span><\/strong><\/div>\n<p><strong><span style=\"color: #ffffff;\">DC01 is the Server name of the Source Domain Controller<\/span><\/p>\n<div><strong><span style=\"color: #ffffff;\">INFO:<\/span><\/strong><\/div>\n<p><strong><\/p>\n<div><span style=\"color: #ffffff;\">To Modify attributes in AD it is very important that the following format be followed for the import file, especially the &#8220;-&#8221; 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: <span style=\"color: #ff0000;\">ldifde -i -f Import.ldf -s <em>Server<\/em>.<\/span><\/span><\/div>\n<p><span style=\"color: #ffffff;\">Sample Import\/Modify File Format:<\/p>\n<div><span style=\"font-size: x-small;\"><span style=\"font-size: x-small;\"><span style=\"color: #ffffff;\">dn: CN=Jane Doe,OU=UserAccounts,DC=harun,DC=se<\/span><\/span><\/span><\/div>\n<p><\/span><span style=\"font-size: x-small;\"><span style=\"font-size: x-small;\"><span style=\"color: #ffffff;\">changetype: modify<\/span><\/p>\n<p><span style=\"color: #ffffff;\">replace: extensionAttribute1<\/span><\/p>\n<p><span style=\"color: #ffffff;\">extensionAttribute1: Staff<\/span><\/p>\n<p><span style=\"color: #ffffff;\">&#8211;<\/span><\/p>\n<p><span style=\"color: #ffffff;\">dn: CN=John Doe,OU=UserAccounts,DC=harun,DC=se<\/span><\/p>\n<p><span style=\"color: #ffffff;\">changetype: modify<\/span><\/p>\n<p><span style=\"color: #ffffff;\">replace: extensionAttribute1<\/span><\/p>\n<p><span style=\"color: #ffffff;\">extensionAttribute1: Staff<\/span><\/p>\n<p><span style=\"color: #ffffff;\">&#8211;<\/span><\/p>\n<p>\u00a0<\/p>\n<div><strong><span style=\"color: #ffffff;\">How to Import multivalued attributes <\/span><\/strong><\/div>\n<p><\/span><\/span><strong>\u00a0<\/p>\n<p><\/strong><\/strong><\/strong><\/p>\n<p><span style=\"color: #ffffff;\">Import files with multivalued attributes have the form of:<br \/>\ndn: <em>distinguishedName<\/em><br \/>\nchangetype: modify<br \/>\nreplace: attribute<br \/>\nmodify replace: <em>attribute<\/em> [this is the attribute to be changed]<br \/>\nattribute: <em>value1<\/em><br \/>\nattribute: <em>value2<\/em><br \/>\nattribute: <em>valueN<\/em> [where N is the next value] &#8211; [hyphen, required to terminate input file]<br \/>\nexample:<br \/>\n<span style=\"color: #ff0000;\">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<\/span><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><span style=\"color: #ff0000;\"><span style=\"color: #ffffff;\"><span style=\"color: #808080;\"><strong>LDIFDE Parameters<\/strong><br \/>\n-i\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Turn on Import Mode (The default is Export)<br \/>\n-f filename\u00a0\u00a0\u00a0\u00a0 Input or Output filename<br \/>\n-s servername\u00a0\u00a0 The server to bind to<br \/>\n-c FromDN ToDN\u00a0 Replace occurrences of FromDN to ToDN<br \/>\n-v\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Turn on Verbose Mode<br \/>\n-j\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Log File Location<br \/>\n-t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Port Number (default = 389)<br \/>\n-?\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Help<br \/>\n\u00a0\u00a0\u00a0\u00a0<br \/>\n<strong>Export Parameters<\/strong><br \/>\n-d RootDN\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 The root of the LDAP search (Default to Naming Context)<br \/>\n-r Filter\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 LDAP search filter (Default to &#8220;(objectClass=*)&#8221;)<br \/>\n-p SearchScope\u00a0 Search Scope (Base\/OneLevel\/Subtree)<br \/>\n-l list\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 List of attributes (comma separated) to look for in an LDAP<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 search.<br \/>\n-o list\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 List of attributes (comma separated) to omit from input<br \/>\n-g\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Disable Paged Search<br \/>\n-m\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Enable the SAM logic on export<br \/>\n-n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Do not export binary values<br \/>\n\u00a0\u00a0\u00a0\u00a0<br \/>\n<\/span><span style=\"color: #808080;\"><strong>Import Parameter<br \/>\n<\/strong>-k\u00a0\u00a0\u00a0\u00a0\u00a0 The import will go on ignoring &#8216;Constraint Violation&#8217; and &#8216;Object<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Already Exists&#8217; errors<br \/>\n\u00a0\u00a0\u00a0\u00a0<br \/>\n<strong>Credentials Parameters<\/strong><\/span><\/span><br \/>\n<span style=\"color: #ffffff;\"><span style=\"color: #808080;\">-a\u00a0\u00a0\u00a0\u00a0\u00a0 Sets the command to run using the supplied user distinguished name<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 and password. For example: &#8220;cn=yourname,dc=yourcompany,dc-com<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 password&#8221;\u00a0<br \/>\n-b\u00a0\u00a0\u00a0\u00a0\u00a0 Sets the command to run as username domain password. The default is<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 to run using the <\/span>credentials of the currently logged on user.<\/span><\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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, &#8220;SourceDomain&#8221; is the name of the domain from which objects are exported and &#8220;TargetDomain&#8221; is the name of the domain in which objects are imported. LDIFDE can also be used to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[],"_links":{"self":[{"href":"https:\/\/harun.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/77"}],"collection":[{"href":"https:\/\/harun.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/harun.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/harun.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/harun.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=77"}],"version-history":[{"count":8,"href":"https:\/\/harun.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/77\/revisions"}],"predecessor-version":[{"id":84,"href":"https:\/\/harun.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/77\/revisions\/84"}],"wp:attachment":[{"href":"https:\/\/harun.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/harun.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/harun.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}