The comma separated value directory exchange (csvde) command works on comma-separated value files. Each element in the csv file is separated by a comma, and you can use the csvde command to import or export objects for AD.
Tip
You can only import and export with csvde. You cannot delete objects or make any modifications to objects with csvde. You can import, export, delete, and modify objects with ldifde.
The following table shows some common switches used with csvde.
ldifde Switch | Comments |
---|
-i | Import mode. If not included, the default mode is export. |
-k | Ignores
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 filename | Filename. Identifies the name of the file to use for the import or export operation. |
-b user domain password | Specifies
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 path | Specifies the path for a log file.
Note
This is not the actual file name, but instead just the path. The error log will be named csv.err and can be opened with Notepad.
|
-v | Enables 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 of the accounts from the domain into a file named export.txt:
Tip
The first line shows all of the possible attributes
you can include in a csv input file. It also shows the format of a csv
file. You can open this file in Microsoft Excel or Notepad.
You saw earlier that the ldifde
input file is line delimited with a separate attribute on each line. In
addition, each line identifies both the attribute and the attribute
value (such as changetype: add). In contrast, csvde
is a comma-delimited file with attributes separated by commas. A
significant difference is that the attributes aren’t specified on each
line. Instead, the first line in the csv file is the header line and
identifies the attributes in each of the following lines.
For example, consider the following three lines in a
sample csv file. The first line is the header line and identifies what
attributes are in each of the other lines. The second and third lines
provide the data for the user accounts.
Line | Contents of Each Line in csv File |
---|
Header line | dn, objectclass, samaccountname, userprincipalname, displayname, useraccountcontrol
|
First user | "cn=Dawn, ou=west, ou=sales, dc=pearson, dc=pub", user, Dawn, Dawn@pearson.pub, Dawn Grzena, 514
|
Second user | "cn=Bob,ou=west,ou=sales,dc=pearson,dc=pub", user, Bob, Bob@pearson.pub, , 514
|
There are some important points you need to recognize:
First, the order of the attributes in each
line must follow the same order in the header line. For example, the DN
is first, the objectclass is second, and so on.
Second,
because the DN includes commas, the entire DN must be enclosed in
quotes; otherwise, each comma in the DN will be interpreted as a
different attribute and the command will fail.
Third, you can skip an attribute value by adding a comma without a value. For example, in the second user line, the displayname attribute is not included; instead, there is simply an extra comma.
If you have a file named csuser.csv with the three
lines in the preceding table, you can use the following command to
input the two users into the domain. The -i-f indicates the file is csuser.csv, the -v specifies a verbose output, and the -j creates the error log in the c:\de folder. indicates it is an import, the
csvde -i -f csuser.csv -v -j c:\de
Figure 1 shows the accounts created with the previous command.