Creating Many User Accounts

User-specific scripts work well if you have to create only a few user accounts. If you need to create many user accounts at one time, or if you create new accounts often, using a script with an input file is more efficient. The input file includes the user data so that you can use the script to create any user account. For example, the output shown below represents the users-to-create.txt input file that provides the user data for the universal script in Example 21-3. Although this input file includes only four data sets, you can include as many data sets as you want. You include a data set for each user account that you want to create.

vlaunders:12/09/01:The description:Victoria Launders:onebanana
aglowenorris:08/07/00:Another user:Alistair Lowe-Norris:twobanana
kbemowski:03/03/03:A third user:Karen Bemowski:threebanana
jkellett:08/09/99:A fourth user:Jenneth Kellett:four

As the output shows, each data set goes on a separate line. A data set can contain as many values as you want. The data sets in the users-to-create.txt file have five values: username, expiration date, description, full name, and password. You use colons to separate the values.[24]

Example 21-3. Creating many user accounts using a script with an input file

Option Explicit Const ForReading = 1 Dim objDomain, objUser, fso, tsInputFile, strLine, arrInput Dim fldUserHomedir, wshShell Set objDomain = GetObject("LDAP://cn=Users,dc=mycorp,dc=com") Set fso = CreateObject("Scripting.FileSystemObject") ...

Get Active Directory, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.