4.25. Importing Objects Using an LDIF File
Problem
You want to import objects into Active Directory using an LDIF file. The file could contain object additions, modifications, and/or deletions.
Solution
Using a command-line interface
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
Discussion
For more information on the LDIF format, check RFC 2849.
Using a command-line interface
To import with ldifde, simply specify the
-i switch to turn on import mode and
-f
<filename> for
the file. It can also be beneficial to use the -v
switch to turn on verbose mode to get more information in case of
errors.
See Also
Recipe 4.24 for information on LDIF, RFC 2849 (The LDAP Data Interchange Format (LDIF)—Technical Specification), and MS KB 237677 (Using LDIFDE to Import and Export Directory Objects to Active Directory)