How to Create a Contact in an Exchange Organization with VBScript
VBScript for Creating Contacts in an Exchange Organization
On this page, I will explain how to create a Contact which appears in the Exchange GAL (Global Address List). Example 1 creates a single Contact, where as Example 2 explains how to bulk import the names and addresses from a spreadsheet. In both examples, there are three crucial fields legacyExchangeDN, mailNickname and targetAddress.
It is only common sense that the more LDAP fields that you have in your script the greater the scope for error. Therefore, if you are not familiar with creating Contacts, I suggest you start with my simple Contact script.
Topics for Creating Simple Contacts with a VBScript
Always remember that VBScript simply mimics steps that you take manually. So, try creating a Contact with the Active Directory Users and Computers menus. However, if the wizard asks for Exchange 2003 information such as Associated Administrative Group, then that is an indication that VBScript will require extra fields, for example, legacyExchangeDN, mailNickname and targetAddress.
There are at least two traps to avoid, firstly, a surprise, we don't need sAMAccountName because the Contact will never actually logon to the domain.
Secondly, rather than the Mail LDAP field, we need to script targetAddress and possibly proxyAddresses. For a long time I thought VBScript was case insensitive, however with targetAddresses, SMTP (UPPER case) indicates the primary email address, where as smtp (lower case) means a secondary email address.
Example 1 - Script to Create a Contact in an Exchange Organization
Recommended: that you logon as administrator, preferably at a domain controller. Remote Desktop would be a suitable alternative. If that is not possible, you could get these sample scripts to work from an XP machine as a non-administrator, but why introduce extra complications? At the beginning you want easy success, with fewest obstacles.
Instructions for Creating a Contact in Active Directory
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.
Script to Create a Contact in your Active Directory
Note 1: The header section, in the first 11 lines, explains the purpose of the script and declares the variables.
Note 2: One of the most difficult LDAP fields is legacyExchangeDN. In the script I manipulate legacyExchangeDN with strMailbox. The point is that you need to examine your Exchange Organization, then edit /o=GuyWorld.
Note 3: In many ways this script is messy and convoluted, as you may have guessed, it's preparing you for the bulk import in Example 2, where we read the values from columns in a spreadsheet.
Here is a free tool to monitor your Exchange Server. Download and install the utility, then inspect your mail queues, monitor the Exchange server's memory, confirm there is enough disk space and check the CPU utilization.
This is the real deal - there is no catch. SolarWinds provides this fully-functioning freebie, as part of their commitment to supporting the network management community.
Prerequisites for Creating Contacts from a Spreadsheet
Each Contact will occupy one row of the spreadsheet, for example MrsAcme in Row 3. Each attribute will always be in the same column, for example, everyone's legacyExchangeDN address is in Column J (10th Column). Here is a sample spreadsheet.
Create a spreadsheet with your prospective Contacts' properties. My advice is to spend time researching the LDAP attributes, which correspond to what you see in an Active Directory Users and Computers property sheet. See more on LDAP properties here.
Be aware that where you save this .xls file should correspond to the strPathExcel variable in the script below. For example: E: \scripts\ContactExcel .xls.
VBScript Tutorial - Learning Points
Note 1: Observe how we open and close the Excel spreadsheet by manipulating the objExcel object. (Starting at line 27). Set objExcel = CreateObject("Excel.Application")
Note 2: The Contact's attributes are read from Excel Spreadsheet using the .cell property.
Note 3: Trace the data in the spreadsheet to lines 31-40 in the VBScript. At first, it is confusing the way that Column A hold values for the CN, but the VBScript referenced Column A as intRow, 1. Once you realize that the 1 (in intRow,1), refers to Column A, and 2 would be Column B, then the picture becomes clearer. Do go back over this method as it is the cornerstone for so many spreadsheet / VBScript interactions.
Note 4: The Contact object is build with command: objContainer.Create("Contact",_
Contacts could be a case study for how to employ VBScripts to create Active Directory objects. The secret is to build your VBScripts gradually. Start with scripts which contain the actually values. Then progress to bulk import scripts, which open a spreadsheet and then read the those values from the .cell properties.
See More Active Directory VBScripts featuring contacts