Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


March 2005

Create a Bunch of User Accounts in a Flash

CSVDE is a flawed Addusers successor
RSS
Subscribe to Windows IT Pro | See More Active Directory (AD) Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

One of the most common laments I hear from overworked administrators is, "I need to quickly create a large number of user accounts in my Windows Server 2003 domain, and I think I'd wear out my mouse button if I used the Microsoft Management Console (MMC) Active Directory Users and Computers snap-in to complete the task. Is there a better way?"

Actually, there are many better ways. For example, both Windows 2003 and Windows XP ship with the Dsadd Users utility, a command-line tool that creates user accounts. A little copy-and-paste work in Notepad can create a batch file for creating any number of users in a flash. Windows 2000 Server and later ships with createusers.vbs, a VBScript script in Support Tools that creates a user account and even includes an /I: option that lets you feed it a list of usernames to create. The Net Users username /Add command has been around, if memory serves, since the Windows NT 4.0 days (and perhaps even earlier), offering another command-line user-creation tool that, again, you can transform into a powerful batch tool in Notepad.

My personal favorite is Addusers (addusers.exe), an old Microsoft Windows NT Server 4.0 Resource Kit tool that lets you export SAM and Active Directory (AD) files to simple ASCII comma-delimited (CSV) files, then import those CSV files to create users in bulk. Unfortunately, Microsoft has replaced Addusers with two other bulk tools: Comma Separated Value Data Exchange (CSVDE) and Lightweight Data Interchange Format, Data Exchange (LDIFDE). Both have their strengths and weaknesses. This month, I want to talk about CSVDE.

CSVDE Nuts and Bolts
Like Addusers, CSVDE lets you export the AD contents of a source domain to a comma-separated value ASCII file, then import a CSV file to create user accounts en masse in a target domain. But whereas Addusers understands only NT 4.0–type accounts, CSVDE understands the new user characteristics of AD users. For example, Addusers doesn't let you specify a user principal name for a user, but CSVDE does.

You can use the simplest of CSVDE commands to export the contents of AD:

csvde -f export.csv

Doing so produces a file called export.csv, which shows the current objects in the source domain's AD database. Why would you want to export from an existing domain? Because an exported CSVDE file is in roughly the format CSVDE needs to see as input for an imported file, so it can help guide you in troubleshooting CSVDE import problems. If you're having trouble creating a usable file for CSVDE and you keep getting errors because the file isn't correctly formatted, looking at a file exported from an existing domain provides a working example of what CSVDE wants to see. You can look at the exported file in Notepad, but CSV-format files are better viewed in Microsoft Excel, which presents the file's fields in orderly columns.

For optimum viewing in Excel, press Ctrl+A to select the entire file, then Format, Column, Autofit Selection to widen the viewing area for columns that have a lot of data or shrink columns that contain little or no data. A quick view of an exported AD file reveals that it's huge. Because CSVDE dumps all AD objects—Group Policy Objects (GPOs), machine accounts, OUs, the domain itself—you get a lot of records that you really don't care about if you just want to create user accounts. Therefore, use the -r ("restrict") option to tell CSVDE to export only the user objects:

csvde -f export.csv -r "(objectClass=User)"

The resulting file will have many columns, most of which you won't need when you're creating a suitable-for-import CSV file. The fields you'll probably find useful are DN (distinguished name), objectClass (user), name (user's full name), cn (same as the full name), displayName (same as the full name), givenName, sn (surname), profilePath, mail, sAMAccountName (your "pre-Windows 2000 logon name") and userPrincipalName. If you've used the Active Directory Users and Computers snap-in to populate fields—such as Manager, Office and so on—you might have others. You'll have to experiment to determine exactly which fields work beyond the ones that I've listed.

CSVDE Limitations
Now, you'd think that you could pump that CSV file back into CSVDE as an input and obtain a brand-new AD instance containing the same objects—as Addusers lets you do—but unfortunately that process won't work, for a few reasons. The primary reason is that CSVDE also exports things such as SIDs ("objectSID"), which are exportable but not importable. Trying to feed CSVDE an import file with the objectSID field (which an export offers) will result in the error message

Add error on line 2: Unwilling To Perform

The server-side error is Access to the attribute is not permitted because the attribute is owned by the Security Accounts Manager (SAM).

Don't try to understand that message from the text. It's true meaning is, "There are some things that CSVDE just plain can't do." If you restrict yourself to the fields I named earlier, you won't see the SAM error message. Also, if you create a CSV file from scratch, you must be careful to spell the field names exactly as a CSV export shows them and as I've written them here—CSVDE is case-sensitive. You can, by the way, use the -m option to tell CSVDE to skip any fields that would give it heartburn, as in the command

csvde -f export.csv -m -r "(objectClass=User)"

After you have a suitable-for-importing file, use the -i option to import it:

csvde -f filetoimport.csv -i

CSVDE has a few other limitations. First, you can't use it to set passwords. Therefore, after you create a pile of users, you'll need to set their passwords some other way—in my next column, I'll show you how to do so easily and automatically with a VBScript script. Second, all accounts that you create through CSVDE lack passwords and are disabled, but Windows 2003 domains require complex passwords by default. You'll need to enable those accounts after setting their passwords. Finally, and incomprehensibly, CSVDE can't assign user accounts to security groups. You can use the tool to create a bunch of users, but if you try to use the Member Of attribute to put them into the Accountants group, you'll get the SAM error message.

Stay Tuned...
Overall, CSVDE is a mildly disappointing Addusers successor. You can work around some of its flaws by using a bit of scripting, which I'll talk about next time.

End of Article



Reader Comments
very good

jessbuckley February 18, 2007 (Article Rating: )


You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
Friday at PASS Europe 2006

Kevin talks about the closing day of the event and shares a funny Microsoft film. ...

More fun TechEd 2005 Resources

Kevin points out some more TechEd resources ...

What service packs and fixes are available?

...


Active Directory (AD) Whitepapers Sustainable Compliance: How to reconnect compliance, security and business goals

User Provisioning and Access Control

Managing Unix/Linux with Microsoft System Center Operations Manager 2007 Cross Platform Extensions Beta

Related Events Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

Keeping Your Business Safe from Attack: Monitoring and Managing Your Network Security

Windows 2003: Active Directory Administration Essentials

Related Active Directory (AD) Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.

Job Openings in IT


ADS BY GOOGLE SPONSORED LINKS FEATURED LINKS

Microsoft Exchange & Windows Connections event returns to Las Vegas Nov 10 - 13
Connections returns to Las Vegas for this exciting event where each attendee will receive SQL Server 2008 standard with 1 CAL. Co-located with Microsoft ASP.NET, SQL Server, and SharePoint Connections with over 250 in-depth sessions.

Free Online Event! Virtualization:Get the Facts!
Register now and attend this free, live in-depth online conference on November 13 and 20, 2008, produced by Windows IT Pro. All registrants are eligible to receive a complimentary one-year digital subscription to Windows IT Pro (a $49.95 value)!

Check Out Hyper-V Video on ITTV
Watch Karen Forster's interview on Hyper-V's performance on ITTV.net.

Ease Your Scripting Pains with the Flexibility of PowerShell!
Join MVP Paul Robichaux on December 11, 2008 at 11:00 AM EDT as he equips you with PowerShell basics in 3 introductory lessons, each followed by a live Q&A session—all on your own computer!

PASS Community Summit 2008 in Seattle on Nov 18-21
The don’t-miss event for Microsoft SQL Server Professionals. Register now and you’ll enjoy top-notch Microsoft and Community speakers and more.



Solving PST Management Problems
In this white paper, read about the top PST issues and how to administer local/network PST Files.

Get Protected -- Data Protection Manager 2007
Protect your virtualized environment with Data Protection Manager

Order Your SQL Fundamentals CD Today!
Learn how to use SQL Server, understand Office integration techniques and dive into the essentials of SQL Express and Visual Basic with this free SQL Fundamentals CD.

Maximize Your SharePoint Investment: Get Your Data Moving
Watch this web seminar now to learn how to maximize your SharePoint investment! Join us as we take a look at the complex business of securing, accessing and managing vast amounts of information in a global network and various ways to get your data moving.
Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing