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
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)
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.
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 To
500
In this script the usernames are Bulkuser1, Bulkuser2... Change the
name if you wish.
- Copy the entire Script in the green box below.
- Paste it into notepad.exe.
- File (menu), Save as Bulky.vbs. Note: This is where people go
wrong, remember the .vbs extension.
- Double click Bulky.vbs
- 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 See Also
|