Introduction to creating users with a VBScript
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
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”
Set objContainer = GetObject(“LDAP://OU=BulkGuy,” & _
For account = 1 To 20
Set objLeaf = objContainer.Create(“User”, “cn=” & strName & account)
objLeaf.Put “sAMAccountName”, strName & account
intUser = intUser +1
WScript.Echo intUser & ” Users created “
- 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.
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)
VBScript method 2 works like mail-merge. An Excel spreadsheet holds the data, while a VBScript reads the users’ properties, and then creates the user object in Active Directory. A bonus of this method is that spreadsheet acts as a record for who you have added to your domain.
The script needs a ‘Loop’ to read the properties from each row and so generate a succession of new users. I have a section in the ebook explaining Do… Until Loop routines. See Do…Loop Until
The crucial feature of the spreadsheet is the first row which holds the LDAP properties for the users. This similar to creating field names for a database. A key skill is to deduce the LDAP names which correspond to the user properties; for example the LDAP name for First Name is givenName.
Now, I have a brand new ebook which has a great script to create users. What you get in the ebook are step-by-step instructions to customize the example script to suit your own domain. You also get a excel spreadsheet with LDAP properties in the first row. The ebook is divided into 10 sections each page explains a feature of the script in detail.