Exporting and Importing Objects Using LDIF or CSV

The LDAP Data Interchange Format (LDIF) specification defined in RFC 2849 describes a well-defined file-based format for representing directory entries. The format is intended to be both human and machine parseable, which adds to its usefulness. LDIF is the de facto standard for importing and exporting a large number of objects.

While LDIF is useful for exchanging data between different LDAP servers, CSV is useful for exchanging data between Microsoft utilities, notably Excel. Once you have a CSV file containing entries, you can use Excel to view, sort, and manipulate the data.

The first line of a CSV file, as you can see from the example in the solution, lists the fields set by subsequent lines. Each subsequent line specifies values for one entry to be added. If you have a spreadsheet containing objects you want to import, first save it as a CSV file and use csvde to import it. You cannot modify attributes of an object or delete objects using csvde.

Using a command-line interface

The following command exports objects using LDIF:

> ldifde -f output.ldf -l  -p  -r "" -d ""

To import objects using the ldifde utility, you must first create an LDIF file with the objects to add, modify, or delete. Here is an example LDIF file that adds a user, modifies the user twice, and then deletes the user:

dn: cn=jsmith,cn=users,dc=rallencorp,dc=com
 changetype: add
 objectClass: user
 samaccountname: jsmith
 sn: JSmith
 useraccountcontrol: 512
dn: cn=jsmith,cn=users,dc=rallencorp,dc=com
 changetype: modify
 add: givenName
 givenName: Jim
 replace: sn
 sn: Smith
dn: cn=jsmith,cn=users,dc=rallencorp,dc=com
 changetype: delete

Once you’ve created the LDIF file, you just need to run the ldifde command to import the new objects.

> ldifde -i -f input.ldf

The following command exports objects from a CSV file:

> csvde -f output.csv -l  -p  -r "" -d ""

To import objects using the csvde utility, you must first create a CSV file containing the objects to add. The first line of the file should contain a comma-separated list of attributes you want to set, with DN being the first attribute. Here is an example:


The rest of the lines should contain entries to add. If you want to leave one of the attributes unset, leave the value blank (followed by a comma). Here is a sample CSV file that would add two user objects.


Once you’ve created the CSV file, you need to run the csvde command to import the new objects:

> csvde -i -f input.csv