Introduction to creating users with a VBScript
Note1 : I have a new improved script to create a user Note 2: I have a VBScript to create users
from an Excel Spreadsheet I have two VBScripts which will create your users accounts in Active Directory.
The first method is relatively straightforward, the second method is more
useful, but needs a spreadsheet holding the user properties.
The strength of this script is that it will create users in any domain. Its
statements are designed to get you started in your quest to script new user
accounts.
' VBScript to create an OU called BulkGuy
' VBScript then creates 20 Users in OU BulkGuy
' Guy Thomas - January 2004
Dim objRoot, objDomain, objOU, objContainer
Dim strName
Dim intUser
strName ="BulkGuy"
Set objRoot = GetObject("LDAP://rootDSE")
Set objDomain = GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))
Set objRootDSE = GetObject("LDAP://rootDSE")
Set objOU=objDomain.Create("organizationalUnit", "ou=BulkGuy")
objOU.Put "Description", "Guy's Bulk Users OU"
objOU.SetInfo
Set objContainer = GetObject("LDAP://OU=BulkGuy," & _
objRootDSE.Get("defaultNamingContext"))
For account = 1 To 20
Set objLeaf = objContainer.Create("User", "cn=" & strName & account)
objLeaf.Put "sAMAccountName", strName & account
objLeaf.SetInfo
intUser = intUser +1
Next
WScript.Echo intUser & " Users created "
WScript.quit
Learning Points
- On line 9, just after the variables are declared, is the statement: strName = "BulkyGuy";
perhaps you
would like to change this string to reflect your name.
- The reason the script works in any domain is the command: GetObject("LDAP://rootDSE").
This statement means - use LDAP to get the root domain.
- For account = 1 To 20. You could amend this to create more, or less
accounts. Note the 'Next' later in the script which makes the routine loop,
and this what creates multiple users.
- Technically, cn and sAMAccountName are the only two mandatory properties
for the user object. With Method 1, it is easier to add more
user properties, such as sn = Last Name.
|