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.
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.
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.
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.
Import users from a spreadsheet, complete with their mailbox. Just provide a list of the users with the fields in the top row, and save as .csv file. Then launch this FREE utility, match your Exchange fields with AD's attributes, click and import the users. Optionally, you can provide the name of the OU where the new mailboxes will be born.
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,
Here is how I bolted the steps together.
Instructions for Creating a Mailbox-Enabled User.
' homeMDB .vbs
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.
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.