15.15. Exporting and Importing Objects Using LDIF or CSV


You want to import or export objects in mass. There are two ways to do this: via an LDIF file or comma-separated value file.


Using a graphical user interface

None of the standard Microsoft GUI tools support importing or exporting Active Directory data with LDIF or CSV.

Using a command-line interface

The following command exports objects using LDIF:

> ldifde -f output.ldf -l <AttrList> -p <Scope> -r "<Filter>" -d "<BaseDN>"

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 <AttrList> -p <Scope> -r "<Filter>" -d "<BaseDN>"

To import objects using the csvd e 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 ...

Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.