WSH – Bulk Creation of New Users

Introduction – Bulk creation of users with WSH

For a bulk import of new users, WSH (Windows Scripting Host) is an ideal method to automatically generating new user accounts. [I strongly recommend you work through WSH – Create User before tackling this page.]

WSH Topics

 ♦

Create the OU

To prevent all the users being created in the default Users container, we need to create an OU.  This is taken care of by this line:
Set objOU=oDomain.Create("organizationalUnit", "ou=BulkImport")

Note: The syntax is OU=BulkImport (Not CN=BulkImport or CN = Users)

Set the Object

Here we tell the script where to create the users
Set objContainer = GetObject("LDAP://OU=BulkImport," & _
objRootDSE.Get("defaultNamingContext"))

Note: Check that the name of the OU (BulkImport) matches in both parts of the script.

Looping with For …. Next

This script creates 10 users, it would be so easy to create 500 by changing
For i = 1 To 10   For example,  increase 10 to 500: For  i = 1 To500

In this script the usernames are Bulkuser1, Bulkuser2…  Change the name if you wish.

Instructions

  1. Copy the entire Script in the yellow box below.
  2. Paste it into notepad.exe.
  3. File (menu), Save as Bulky.vbs.   Note: This is where people go wrong, remember the .vbs extension.
  4. Double click Bulky.vbs
  5. Go to Active Directory Users and Computers, Press F5, observe the BulkImport OU.

‘Script to Create multiple users in an OU called BulkImport
‘Script created by Guy Thomas
‘Feel free to adapt names
Dim objOU

Set oRoot = GetObject("LDAP://rootDSE")
Set oDomain = GetObject("LDAP://" & oRoot.Get("defaultNamingContext"))

Set objRootDSE = GetObject("LDAP://rootDSE")
Set objOU=oDomain.Create("organizationalUnit", "ou=BulkImport")
objOU.Put "Description", "Guy’s Bulk Import OU"
objOU.SetInfo

Set objContainer = GetObject("LDAP://OU=BulkImport," & _
objRootDSE.Get("defaultNamingContext"))

For i = 1 To 10
Set objLeaf = objContainer.Create("User", "cn=BulkUser" & i)
objLeaf.Put "sAMAccountName", "BulkUser" & i
objLeaf.SetInfo
Next

WScript.Echo "Congratulations, 10 Users created Remember to Press F5"

If you get an error message – check this page

Guy Recommends:  SolarWinds’ Free Bulk Import ToolFree Download Solarwinds Bulk Import Tool

Import users from a spreadsheet.  Just provide a list of the users with their fields in the top row, and save as .csv file.  Then launch this FREE utility and match your fields with AD’s attributes, click and import the users.

Optionally, you can provide the name of the OU where the new accounts will be born. Download your FREE bulk import tool.

If you need more comprehensive software, download a free trial of SAM (Server & Application Monitor)

See Also