Location: Articles

Your Home Page ..

Site Articles:

Add to Google

Add to My Yahoo!

Mail List Posts:

Add to Google

Add to My Yahoo!

Friends

Friends

ScriptLogic
Articles

Articles

VBScript to create a large number of mailbox-enabled user accounts

By on Sunday, November 25, 2007 9:13 PM

Sometimes when you’re testing something you have a need to create a large number of users. In my case I wanted to create users but also have them mailbox-enabled (for Exchange 2003) at the same time. This VBScript sample provides a quick and easy method of achieving the desired result.

When I went Googling for same sample code that would give me what I wanted, I found lots of examples showing how to create user accounts and a few showing how to create mailboxes.  What I didn’t find was an example of how to create a large number of mailbox-enabled users.  In the end I borrowed heavily from two examples: one from Robbie Allen’s Active Directory Cookbook and another from the Exchange Server Cookbook by Devin Ganger, Missy Koslosky and Paul Robichaux.

One thing to note is that the code must be run on an Exchange server or at least a machine that has the Exchange System Management Tools installed.

Also be aware that this is designed purely for testing.  The password is the same for all accounts and the user attributes populated are the bare minimum.

 

Be aware that the Distinguished Name of the homeMDB is usually quite long and you will probably have to split it over several lines as I have done in the example above.
 
The output should look something like this:
Created User47
Successfully mailbox-enabled user.
Created User48
Successfully mailbox-enabled user.
Created User49
Successfully mailbox-enabled user.
Created User50
Successfully mailbox-enabled user.
 
Created 50 users
Alexei
23/09/2006

 

' This VBScript code creates a large number of users with incremented user names
' e.g. User1, User2, User3, ....
' The code also mailbox-enables the users

' ---------------------------------------------------------------
' The code includes extracts from the book "Active Directory Cookbook"
' by Robbie Allen
' and “Exchange Server Cookbook”
' by Devin Ganger, Missy Koslosky, and Paul Robichaux
' Publisher: O'Reilly and Associates
' ---------------------------------------------------------------

' ------ SCRIPT CONFIGURATION ------
intNumUsers = 50         ' Number of users to create
strParentDN = "OU=User Objects,DC=myco,DC=com" ' DN of where the users will be created
strHomeMDB = "CN=Mailbox Store (DCN1),CN=First Storage Group,CN=InformationStore,CN=DCN1," &_
             "CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=myco," &_
             "CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=myco,DC=com" 

' ------ END CONFIGURATION ---------

' Taken from ADS_USER_FLAG_ENUM
Const ADS_UF_NORMAL_ACCOUNT = 512

set objParent = GetObject("LDAP://" & strParentDN)

for i = 1 to intNumUsers

   strUser = "User" & i
   strPwd = "Password1"
   Set objUser = objParent.Create("user", "cn=" & strUser)
   objUser.Put "sAMAccountName", strUser
   objUser.SetInfo

   objUser.Put "userAccountControl", ADS_UF_NORMAL_ACCOUNT
   objUser.SetPassword(strPwd)

   objUser.AccountDisabled=FALSE

   objUser.SetInfo

   WScript.Echo "Created " & strUser

   objUser.CreateMailBox strHomeMDB

   objUser.SetInfo()

   Wscript.Echo "Successfully mailbox-enabled user."

next

WScript.Echo ""

WScript.Echo "Created " & intNumUsers & " users"


Rating
Comments

By AD Tester @ Monday, January 21, 2008 5:01 PM

Have you tested this script with Exchange Server 2007 and are any tweaks needed to make this work on Exchange Server 2007?


Click here to post a comment
Friends

Friends

Namescape

Ads

AdventNet Banner
Copyright 2008 ActiveDir.org
Terms Of Use