DESKTOP

Windows Server 2008 : Working with Active Directory Accounts - Using ldifde to Export, Import, and Delete Accounts

10/28/2013 7:22:17 PM

The ldifde command works on line-delimited, or line-separated values within files. You can use it to import or export data into or out of Active Directory (AD). You execute these commands on a domain controller (while logged on with an account with administrative permissions).

Tip

The L in ldifde represents the Lightweight Directory Access Protocol, and dif represents data interchange format. The last two letters (de) represent directory exchange.


The following table shows some common switches used with ldifde.

ldifde SwitchComments
-iImport mode. If not included, the default mode is export.
-kIgnores errors. Enables the operation to continue even if there are errors. The lines with errors are not processed, but other lines are as long as they aren’t dependent on the line that had an error. If omitted, the operation stops at the first error and none of the lines are processed.
-f filenameFilename. Identifies the name of the file to use for the import or export operation.
-b user domain passwordSpecifies the username, domain, and password of the account to run the operation. If not specified, the command runs under the context of the currently logged-on user. If the user has appropriate permissions, this switch is not needed.
-j pathSpecifies the path for a log file.

Note

This is not the actual filename but instead just the path. The error log is named ldif.err and can be opened with Notepad.

-vEnable verbose mode. This provides the most words in the output and is useful when troubleshooting problems with the command.

Use the following command to export all the accounts from the domain into a file named export.txt:

ldifde -f ldexport.txt

Tip

You can learn a lot about the different attributes used with ldifde by browsing through the export.txt file created from this command.


When importing accounts, you need a file that includes the accounts in a line-delimited format. Each line identifies specific attributes of an account, and the formatting of this file is critical. The following table shows some of the elements you can add to the file.

Input File AttributesComments
# commentsYou can add comments with a hash mark. The ldifde command ignores comments.
dn: dnThe distinguished name (dn) attribute identifies the account name and location using a distinguished name.
changetype: {add | modify |
delete}

This identifies whether you’ll be adding, modifying, or deleting accounts.
objectclass: {user | computer
| organizationalunit}

You can create users, computers, organizational units, and more by identifying them in the objectclass attribute.
samaccountname: nameThe SAM account name shows the account in the legacy (pre-Windows 2000) name format. Figure 1 shows the SAM account name for a user in the text box to the right of the text box labeled PEARSON\.

Note

The SAM account name is sometimes listed as domain-name\account-name; however, you need only the account name for the ldifde file.

userprincipalname: upnThe user principal name (upn) looks like an email address. It’s created by combining the user logon name with a suffix that identifies the domain. In Figure 1, the UPN is DarrilGibson@pearson.pub.
displayname: nameThis is the name listed in the General tab of the account properties in the Display Name text box. In Figure 1, it is Darril Gibson (with a space) in the Sales\East OU.

Note

This is not the name displayed in the Active Directory Users and Computers (ADUC) console. That name is derived from the common name (CN) attribute in the DN.

givenname: firstnameThe first name is identified as given name.
sn: lastnameThe last name is identified as sn.
useraccountcontrol: {512 |
514}

You can specify that the account is enabled (512) or disabled (514) with the useraccountcontrol attribute.

Tip

If you don’t specify the password, or if the password doesn’t meet the complexity requirements, the command will fail unless you use 514 to disable the user.


Figure 1. User account in ADUC

As an example, you can use the following data in a file named ldou.txt:

#create an OU
dn: ou=test,dc=pearson,dc=pub
changetype: add
objectclass: organizationalunit

You can then use the following command to create the Organizational Unit (OU) in the domain:

ldifde -i -f lduser.txt -v -j c:\de

The command specifies that it is an import (-i), from the file named ldou.txt (-f lduser.txt), with a verbose output (-v), and sends error to a log file in the c:\de folder (-j c:\de).

You can delete the OU by using the following data in a file named lddel.txt. Notice that the only difference is that the changetype is delete instead of add, and you don’t need to specify the objectclass.

#create an OU
dn: ou=test,dc=pearson,dc=pub
changetype: delete

The following command deletes the OU:

ldifde -i -f lddel.txt -v -j c:\de

As another example, you can use the following data in a file named lduser.txt to create a user:

#Create a user
dn: cn=Marina,ou=sales,dc=pearson, dc=pub
changetype: add
objectclass: user
samaccountname: Marina
userprincipalname: marina@pearson.pub
displayname: Marina Jonason
givenname: Marina
sn: Jonason
useraccountcontrol: 514

You can then execute the following command to add the user to the domain:

ldifde -i -f lduser.txt -v -j c:\de

The command specifies that it is an import, from the file named lduser.txt, with a verbose output, and logs errors to a file in the c:\de folder.

Figure 2 shows the account created in ADUC.

Figure 2. Marina user account created from ldifde
Other  
  •  Automating Windows 7 Installation : Preparing a System with Sysprep
  •  Automating Windows 7 Installation : Creating Bootable WinPE Media
  •  Automating Windows 7 Installation : Creating Your First Image, Using the Windows Automated Installation Kit
  •  Automating Windows 7 Installation : Getting Familiar with Microsoft Images (part 2) - Creating Operating System Images
  •  Automating Windows 7 Installation : Getting Familiar with Microsoft Images (part 1) - Creating a Bootable VHD Image
  •  Windows 8 : Scheduling Maintenance Tasks - Viewing and Managing Tasks on Local and Remote Systems
  •  Windows 8 : Detecting and Resolving Windows 8 Errors - Using the Event Logs for Error Tracking and Diagnosis, Viewing and Managing the Event Logs
  •  Windows 8 : Using Remote Assistance to Resolve Problems
  •  Windows 8 : Managing Automatic Updates
  •  Windows 8 : Managing Installed and Running Programs (part 3) - Configuring AutoPlay Options, Adding and Removing Windows Features
  •  
    Top 10
    Extending LINQ to Objects : Writing a Single Element Operator (part 2) - Building the RandomElement Operator
    Extending LINQ to Objects : Writing a Single Element Operator (part 1) - Building Our Own Last Operator
    3 Tips for Maintaining Your Cell Phone Battery (part 2) - Discharge Smart, Use Smart
    3 Tips for Maintaining Your Cell Phone Battery (part 1) - Charge Smart
    OPEL MERIVA : Making a grand entrance
    FORD MONDEO 2.0 ECOBOOST : Modern Mondeo
    BMW 650i COUPE : Sexy retooling of BMW's 6-series
    BMW 120d; M135i - Finely tuned
    PHP Tutorials : Storing Images in MySQL with PHP (part 2) - Creating the HTML, Inserting the Image into MySQL
    PHP Tutorials : Storing Images in MySQL with PHP (part 1) - Why store binary files in MySQL using PHP?
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    VIDEO TUTORIAL
    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
    Popular Tags
    Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS