Computer Performance, Windows 2003, Exchange 2003, Logon Scripts

Guy recommends :
Free Solarwinds
VM Console

Solarwinds VM Console Free Download

Find out which of your VMs are a waste of space and which VMs need more resources.



VBScript - Create Users

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.

Method 1 - Self contained VBScript to create users.

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.

Guy Recommends:  Solarwinds' Free Bulk Import ToolFree Download 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.

There are also two bonus tools in the free download, and all 3 have been approved by Microsoft:

  1. Bulk-import new users into Active Directory.
  2. Seek and zap unwanted user accounts.
  3. Find inactive computers.

Download your FREE bulk import tool.


Note1 : I have a new script to create a user

Note 2: I have a VBScript to create users from an Excel Spreadsheet


Method 2 - Reading properties from a spreadsheet

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.

Ebook - How to create users with a VBScript

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.


Download your eBook:  How to create users with a VBScript- only $6.25

How to create users with a VBScriptSave hours of frustration and buy Guy's eBook.  The features include: detailed examples on how to import LDAP properties from a spreadsheet, Do...Loop Until  explained, connect to your domain with RootDSE.

You get a printer friendly version with copy enabled, and no expiry date.

 


See Also

 

 *


Custom Search

Guy Recommends: WMI Monitor and It's Free!Solarwinds WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems.

Fortunately, Solarwinds have created the Free WMI Monitor so that you can actually see and understand these gems of performance information.  Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor

 

Home Copyright © 1999-2012 Computer Performance LTD All rights reserved

Please report a broken link, or an error.