DESKTOP

Windows Server 2008 : Working with Active Directory Accounts - Using csvde to Export and Import Accounts

10/28/2013 7:24:44 PM

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 SwitchComments
-iImport mode. If not included, the default mode is export.
-kIgnores 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 filenameFilename. Identifies the name of the file to use for the import or export operation.
-b user domain passwordSpecifies 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 pathSpecifies 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.

-vEnables 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:

csvde -f csexport.csv

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.

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

Figure 1. User accounts created from csvde
Other  
  •  Windows Server 2008 : Working with Active Directory Accounts - Using ldifde to Export, Import, and Delete Accounts
  •  Automating Windows 7 Installation : Preparing a System with Sysprep
  •  Automating Windows 7 Installation : Creating Bootable WinPE Media
  •  Automating Windows 7 Installation : Creating Your First Image, Using the Windows Automated Installation Kit
  •  Automating Windows 7 Installation : Getting Familiar with Microsoft Images (part 2) - Creating Operating System Images
  •  Automating Windows 7 Installation : Getting Familiar with Microsoft Images (part 1) - Creating a Bootable VHD Image
  •  Windows 8 : Scheduling Maintenance Tasks - Viewing and Managing Tasks on Local and Remote Systems
  •  Windows 8 : Detecting and Resolving Windows 8 Errors - Using the Event Logs for Error Tracking and Diagnosis, Viewing and Managing the Event Logs
  •  Windows 8 : Using Remote Assistance to Resolve Problems
  •  Windows 8 : Managing Automatic Updates
  •  
    Top 10
    Extending LINQ to Objects : Writing a Single Element Operator (part 2) - Building the RandomElement Operator
    Extending LINQ to Objects : Writing a Single Element Operator (part 1) - Building Our Own Last Operator
    3 Tips for Maintaining Your Cell Phone Battery (part 2) - Discharge Smart, Use Smart
    3 Tips for Maintaining Your Cell Phone Battery (part 1) - Charge Smart
    OPEL MERIVA : Making a grand entrance
    FORD MONDEO 2.0 ECOBOOST : Modern Mondeo
    BMW 650i COUPE : Sexy retooling of BMW's 6-series
    BMW 120d; M135i - Finely tuned
    PHP Tutorials : Storing Images in MySQL with PHP (part 2) - Creating the HTML, Inserting the Image into MySQL
    PHP Tutorials : Storing Images in MySQL with PHP (part 1) - Why store binary files in MySQL using PHP?
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    VIDEO TUTORIAL
    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
    Popular Tags
    Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS