Link to home
Start Free TrialLog in
Avatar of ronenshabtay

asked on

Automating User Mailbox Creation with VBScript

Hi Experts,

Is there a way to create a mail-enabled user account in Windows 2000 with a VB script.
 I wrote a script that creates the account, places the account in the right OU and enabled it.
I can't figure out the mail-enable part.There must be a way to do this all in one script.

Thanks for your help

Avatar of nbishop1979

Avatar of ronenshabtay


Thanks for your quick response nbishoop1979,
I am familear with this site (I learn a lot on VBScript from it) but I don't want to do it with CSVDE or Excel.
I just want someone to execute the script and the user account will be complete (user enable, password, mail enable etc')

Microsoft has an article about doing...maybe it would be of some help;en-us;327079&Product=exch2003

are you still seeking a solution to this? i can help out with some vbscirpt code if you still need it.


I manage to write a code that do the job (following is a copy of it) but I will be very hapy
if you could look at it an post your comments or share me with your own codes. I willing
to give the points  for useful comments or codes.


here is my code:

' VBScript to create an OU called QA38Users
' VBSCript then creates, enable and creates mailbox
' to xx Users in OU QA38Users
' ===============================================

Option Explicit
Dim objRoot, objDomain, objOU, objContainer, objUser, objRootDSE
Dim strContainer, strLastUser, strName, strDNSDomain, intCounter, intAccValue, intUser
Dim account, mbxDN, exchUser, objLeaf

strName ="TestUser"

Set objRoot = GetObject("LDAP://rootDSE")
Set objDomain = GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))

Set objRootDSE = GetObject("LDAP://rootDSE")
Set objOU=objDomain.Create("organizationalUnit", "ou=QA38_Test_Users")
objOU.Put "Description", "QA38 Domain Users"

Set objContainer = GetObject("LDAP://OU=QA38_Test_Users," & _

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 "

Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
strContainer = "OU=QA38_Test_Users,"
intAccValue = 512
strContainer = strContainer & strDNSDomain
set objOU =GetObject("LDAP://" & strContainer )
intCounter = 0
For each objUser in objOU
If objUser.class="user" then
objUser.Put "userAccountControl", intAccValue
intCounter = intCounter +1
strLastUser = objUser.Get ("name")
End if
WScript.Echo intCounter & " Accounts Enabled. Value " _
& intAccValue

mbxDN = "CN=Mailbox Store (QA-41),CN=First Storage Group,CN=InformationStore,CN=QA-41," & _
        "CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=QA38," & _
        "CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=qa38,DC=xosoft,DC=com"
For account = 1 To 20            
Set exchUser = objContainer.Create("User", "cn=" & strName & account)  
exchUser.CreateMailbox mbxDN
intUser = intUser +1

No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
PAQ - Points Refunded

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

EE Cleanup Volunteer
Avatar of DarthMod
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial