Last Updated on July 8, 2014 by Dishan M. Francis
In a active directory when it comes to user creation if the number of user accounts are small we can either add them with typical user add wizard or create them using user account templates which i explained in a previous post. But if its a large number of accounts it is not practical to do so. if there is way we can automate this process it will save lot of time and resources.
Not only that, on some occasions we will need to grab information stored in AD. if its small number of users, components can query these information either manually viewing properties, doing AD search etc. but if its large complex setup it will not easy to get the info you need. for ex- lets say we need to get list of users start names with "James" if its 10-50 users still you can go and search users and list there properties. but if its setup which have 500+ users and many OUs it will not practical to do it manually.
so it is definitely advantage if there is sort of automation tools which we can use to import/export/create user account details, other resources details. well good news is AD have this feature inbuilt and we can use these tools for automate this processes. In next few posts I will explain what are these tools and how we can use them.
CSVDE (Comma Separated Value Directory Exchange)
CSVDE is a command-line utility which allows to import/export active directory objects to/from CSV ( Comma-Seperate Value) file. This files can simply open/edit by using Microsoft Office Excel or any other text editor. we cant use this tool to modify or delete entries from active directory.
To use this tool just need to use "Command Prompt" in active directory server with administrator privileges.
We can open the "help" file of this utility by typing csvde /?
Export user attributes using CSVDE
The basic syntax for the export is
csvde -f filename
This will export all the objects in active directory domain. but most of the time we will not need export all info and its will be more useful with filtered info.
There are few parameters we can use to filter the info and which can use to export filtered information.
-d – Specifies the distinguish name of the container. the default value is the domain.
-p – Specifies the scope of the search
–r – Filters the objects returns with -d and -p parameters.
-l – Specifies the attributes which will be exported.
Lets test this will a practical example.
In AD test environment under domain contoso.com i have 3 sales department users called Sales A, Sales B, Sales C
with csvde i'm going to export user list which start their name with text "Sales"
the syntax i will use is
csvde -f C:\Sales\UsersNamedSales.csv -r "(name=Sales*)" -l DN,objectClass,sAMAcountName,sn,givenName,userPrincipalName
in here C:\Sales\UsersNamedSales.csv is the file path to save the CSV file.
-r "(name=Sales*)" filters the attributes which start name "Sales" on it.
-l DN,objectClass,sAMAcountName,sn,givenName,userPrincipalName lists the attributes which will be exported to the file.
once the command is executed its gives following,
according to it, saying its exported 8 entrees successfully to the file. lets open the file from C:\Sales\UsersNamedSales.csv and check. i will use Notepad to open the csv file.
As it shows above its list the users i needed, it also listed some other info as well which uses "Sales" in its attributes.
in next posts lets look in to use of CSVDE tool further.