O'Reilly logo

Windows Server Cookbook by Robbie Allen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

15.15. Exporting and Importing Objects Using LDIF or CSV

Problem

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.

Solution

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required