Computer Performance, VBScript

How to Create a User's Mailbox with VBScript

Tutorial for Creating a User's Mailbox with VBScript

This page covers not only an example script to create a mailbox, but also the strategy and tactics you need to achieve this complex task.  In fact, the secret is to have a spreadsheet full of the correct LDAP attributes needed to add the 4 tabs to user's Active Directory property sheet.

Topics for Creating a User's Mailbox with a VBScript

I imagine that the situation is this, you have just installed Exchange 2003 and now you are turning your attention to the hundreds of new joiners who each need an Exchange Mailbox. There is no hiding from the fact that you face a difficult pains-taking task.  This page will help you break down the task of creating a mailbox into stages, get each stage working, then bolt them together to create a final script.

Our Mission and GoalExamples of Mailbox-enabled user Exchange Properties VBScript

The goal of this page is to script new mailbox-enabled users.  What this script does is add 4 tabs to the User's property sheet.  The benefit is that not only can they logon but also they can send and receive email from your Exchange server.

What is your knowledge of Exchange?  Do you need a refresher with the Exchange System Manager?  Are you familiar with the Exchange organization structure in general, and the mailstore names in particular?  See more on configuring Exchange here.

Good news, I have a separate script to show you how to create a user with VBScript. (See here to create a user ).  That leaves this page free to concentrate on building the 5 extra LDAP attributes, which combine to build the user's mailbox.  The three factors, which combine to make building mailboxes a high error task are:

1) A surprising number of people do not know the names of their Exchange Organization. 

2) People confuse DNS names with Active Directory domain names, they are not always one and the same.

3) Confusion over the LDAP properties, in particular the relationship between the columns in the spreadsheet and the .cell properties in the VBScript.

Here is a common example to illustrate my theme - attention to detail.  For instance, assume that your Exchange Organization is called TopMail.  However, the Exchange System Manager displays TopMail (Exchange).  What do you script?  Does it matter if you use TopMail or TopMail (Exchange)?  The answer is yes it makes a difference, and only plain TopMail would work.

Example - Method to Create a Mailbox-Enable User

Without wishing to confuse you, there are two possible strategies for creating a user's mailbox.  Either you can ask the script to read a single long value from one cell of the spreadsheet, or you can build that long value from commands actually in the VBScript.  Either way, it requires attention to detail both for the structure of the field and the correct names for all the parts.

If (when) your script does not produce the desired results, try the fall back technique of creating a user manually, then using ADSI Edit to check the values of the LDAP fields listed below.

Spreadsheet Preparation

The aim of this part of the mission is to create the values for the imported users in a spreadsheet.  Once these values are correct, we open the spreadsheet from the VBScript and read the LDAP values needed to build the user account, including their mailbox.

Let us examine the 5 Mailbox specific attributes that we must script.  However, before any scripting, as a matter of tactics, I would create a mailbox-enabled user manually.   Next, I would  export Active Directory using CSVDE -f exch.csv and examine the LDAP attributes and values of that newly-created user account.

msExchHomeServerName - Exchange needs to know the name of our Exchange server so that it can deliver the email, here is an example:

/o=CPNou/ou=First Administrative Group/ cn=Configuration/cn=Servers/cn=OurServer

The two components of msExchHomeServerName that you definitely need to change are, the first (o=CPNou) and last (/cn=OurServer).

/o=CPNou.  Change this to the precise name of your exchange organization, you do not need the (Exchange) suffix.  Action --> Check your Exchange System Manager, and or, ADSI Edit.

/cn=OurServer.  What is the name of your Mailbox server?  Check with the Exchange System Manager.

/ou=First Administrative Group.  This is likely to be exactly the same in your situation, but do double check.

/cn=Configuration/cn=Server.  Almost certainly, this section will be the same on your test user.

Note: The msExchHomeServerName attribute does not require the mailbox name, that is covered in the homeMDB attribute.  I cannot emphasise enough, that for successful scripting, or more likely, successful troubleshooting you must take the time to understand what each section of the attribute is doing.

mail - Here is the classic email address format, name@domain.  Assuming you are using an Excel Spreadsheet to hold the account values, you can almost certainly calculate the correct value for the 'name' part of the address from the givenName and sn, for example, = givenName &" " & sn.  There are numerous variations for example, a dot instead of a spaces or shortening the sn with the left(text,4) function.  Remember that the domain part is the email domain, which may, or may not be the same as the DNS domain.  Perhaps you are beginning to see what I mean by attention to detail.

You may also wish to investigate targetAddress.  The format is always smtp: name@domain.  In this instance smtp is case sensitive, SMTP: meaning the default email address, smtp: meaning an alternative recipient address.

®

mailnickname - I advise setting mailnickname = sAMAccountName (Pre-2000 Logon Name).  Again, derive this LDAP attribute with Excel's functions. For example =D2, rather than hard-coding guyt.  In this example I assume that D2 already holds the value guyt.

mDBUseDefaults - A easy field to script, just the value to: TRUE

homeMDB - Research the correct name of the user's Mailstore on the server.  Observe the test user, or launch the Exchange System Manager.  HomeMDB is very difficult to script.  The only way that I succeed was to break the task into a dozen or so steps.  Here is the end result:

CN=GuyStore,CN=First Storage Group,CN=InformationStore,CN=PARIS,CN=Servers,
CN=First Administrative Group,CN=Administrative Groups,CN=CPNou,CN=Microsoft Exchange, CN=Services,CN=Configuration,DC=cpexch,DC=com

Here is how I bolted the steps together.

Instructions for Creating a Mailbox-Enabled User.

  1. You should run this VBScript on a Windows Active Directory domain.
  2. Copy and paste the example script below into notepad or a VBScript editor.
  3. Inspect and change the values of strxyz values.
  4. Save the file with a .vbs extension, for example: homeMDB .vbs.
  5. Double click homeMDB .vbs and check string in the message box.

Script to Create the homeMDB attribute for the Mailbox

 

 

' homeMDB .vbs
' Sample VBScript to create the LDAP string for the mailboxes
' Author Guy Thomas http://computerperformance.co.uk/
' Version 1.4 - May 2005
' -----------------------------------------------------------------'
strServer = "Paris"
strExchangeOrg = "CPNou"
strDomain = "DC=CPEXCH,DC=COM"

' These are the defaults, compare with your server and amend.
strAdminGroup = "First Administrative Group"
strStorageGroup = "First Storage Group"
strStoreName = "Mailbox Store (" & strServer & ")"

' Build LDAP string
strMailbox = strMailbox & "CN=" & strStoreName
strMailbox = strMailbox & ",CN=" & strStorageGroup
strMailbox = strMailbox & ",CN=InformationStore"
strMailbox = strMailbox & ",CN=" & strServer
strMailbox = strMailbox & ",CN=Servers"
strMailbox = strMailbox & ",CN=" & strAdminGroup
strMailbox = strMailbox & ",CN=Administrative Groups"
strMailbox = strMailbox & ",CN=" + strExchangeOrg
strMailbox = strMailbox & ",CN=Microsoft Exchange"
strMailbox = strMailbox & ",CN=Services"
strMailbox = strMailbox & ",CN=Configuration"
strMailbox = strMailbox & "," & strDomain

WScript.Echo "Mailbox " & vbCR & strMailbox

WScript.Quit

' End of Sample User Mailbox VBScript.

VBScript Tutorial - Learning Points

Note 1:  Once the script produces the required value for the homeMDB, then either copy this value into a cell of your spreadsheet, or else retain this block in your VBscript to create a mailbox-enabled user.

Note 2: The secret of success is to double check each element, especially the strExchangeOrg and strDomain.

ˇ

Summary of Creating a User's Mailbox

Creating a mailbox-enabled user is a specialist task.  The secret is to breakdown the complex task of building the mailbox into a series of manageable steps.  Bear in mind that the whole mission is to create a fully functional user object with 17/18 tabs, the purpose of this page is to create just the 4 Exchange specific tabs.  The problem we have to overcome is this, it is more difficult to build these 4 Exchange tabs than all the other 13 tabs put together.

Computer Training Software - Recommended Training VideosGuy Thomas recommends Computer Training Software

Their topics and material are ideal for getting you started with VBScript.  The videos are easy to follow and you can control the pace.  Try their free demo material and then see if you want to buy the full package. See more about VB Script Training CD.


See Also

Create user Accounts               ● Set Password for user account


Creating Exchange mailboxes with VBScriptDownload your eBook: Creating Exchange mailboxes with VBScript- only $6.25

Create mailbox-enabled users.  Add mailboxes to existing users in Active Directory.   Step-by-step instructions on how to use VBScript to generate users with mailboxes.  Combine VBScripts with CSVDE to import users from spreadsheets.

You get a printer friendly version with copy enabled, and no expiry date.  It runs to 55 A4 pages.

 

 

 *


Google

Webcomputerperformance.co.uk

Guy Recommends: SolarWinds Exchange Monitor

Exchange Monitor from SolarWindsHere is a free tool to monitor your Exchange Server

 

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

Please report a broken link, or an error.