Automatically Create User Accounts and Mailboxes in Exchange 5.5

Use the CrUM55 utility

Ethan Wilansky

June 22, 2003

16 Min Read
ITPro Today logo in a gray background | ITPro Today


In "Script User Account and Mailbox Creation," September 2002, http://www.exchangeadmin.com, InstantDoc ID 25843, I discussed how to write a script that creates user accounts and mailboxes in Exchange 2000 Server. In response, I received several email messages from readers who wanted to know how to write a script that creates user accounts and mailboxes in Exchange Server 5.5. The tools required for such a script include Active Directory Service Interfaces (ADSI), Windows Script Host (WSH), and a COM object (AcctCrt.dll), whose source code is contained in the Exchange 5.5 software development kit (SDK). Let's look at how you can use these tools, along with VBScript and a touch of XML, to programmatically create user accounts and mailboxes in Exchange 5.5. I do my best to follow the outline of the previous article. Thus, if you read the previous article, you'll find this article easy to follow.

The System Requirements
The utility that creates Windows NT or Active Directory (AD) user accounts and mailboxes in Exchange 5.5 is called CrUM55. CrUM is short for Create User and Mailbox; 55 designates that this script is designed to create mailboxes in an Exchange 5.5 directory only. To use CrUM55, your network must be running Exchange 5.5 and have a Windows 2000 or NT domain in which you want to create user accounts.

When you manually create user accounts and mailboxes in Exchange 5.5, two possible scenarios exist. In one scenario, you create an NT user account, then create the mailbox. In the other scenario, you create an AD domain user account, then the Active Directory Connector (ADC) automatically creates the mailbox. In either case, Exchange 5.5 automatically assigns the user account SID to a mailbox attribute. When you use CrUM55 to programmatically create user accounts and mailboxes in Exchange 5.5, the script automatically creates the user account and mailbox. CrUM55 uses the user account SID that NT or AD creates to link the account and mailbox.

Before running CrUM55, you need to perform three minor tasks on the client computer on which you intend to run the script. First, you must make sure that you can manually create a user account and mailbox from the client computer.

Second, you must install WSH 5.6. You need version 5.6 because the script uses WSH 5.6's improved method of managing command-line arguments and its XML file format; earlier WSH versions don't support either feature. Windows XP includes WSH 5.6. You can download the WSH 5.6 upgrade for Win2K, NT, Windows Me, and Windows 98 at (http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp).

Finally, you need to copy and register AcctCrt.dll on the client computer on which CrUM55 will run. AcctCrt.dll contains the AcctMgmt class, which the utility needs to associate a user account with an Exchange 5.5 mailbox and to generate a Security Descriptor (SD) for the mailbox. The SD gives the user account permission to use the mailbox. The DLL's source code is part of the Exchange 5.5 SDK. I've compiled the source code for the x86 platform and included it in the CrUM55_Utility.zip file, which you can download from http://www.exchangeadmin.com, InstantDoc ID 39177. After you download CrUM55_Utility.zip, copy AcctCrt.dll to the %systemroot%system32 folder on a computer running an NT-based OS, such as XP, Win2K, or NT. Then, from a command line, type

regsvr32 acctcrt.dll

and press Enter.

The Script Basics
The CrUM55 utility consists of two files: CrUM55.wsf, which contains the XML-based command-line Help for running the script, and CrUM55.vbs, which contains the VBScript code to complete the creation tasks. The version of this tool that I wrote for creating Exchange 2000 mailboxes and AD user accounts consists of only one file—a .wsf file. However, for creating Exchange 5.5 mailboxes and NT or AD user accounts, I found that separating the VBScript code from the XML code made the utility easier with which to work. For more information about the .wsf file format, see "The Script Basics" section of "Script User Account and Mailbox Creation."

You can run CrUM55.wsf from either WScript (the WSH graphical interface) or CScript (the command-line interface). For command-line help with CrUM55.wsf, type

crum55.wsf /? 

or

crum55.wsf 

and press Enter.

When you run CrUM55.wsf from WScript, the .wsf file displays status and Help information in a message box, as Figure 1 shows. When you run CrUM55.wsf from CScript, the .wsf file displays the same information in a command window, as Figure 2 shows.

Whether the Help information appears in a message box or command window depends on which script host you've configured as the default. WScript is the default script host unless you specifically configure WSH to use CScript. To configure CScript as your default script host, type the following code at the command line:

cscript //h:cscript

and press Enter.

CrUM55.wsf requires five parameters (i.e., /a, /u, /d, /f, and /l) to create an NT domain user account and Exchange 5.5 mailbox and six parameters (i.e., /a, /u, /d, /c, /f, and /l) to create an AD domain user account and Exchange 5.5 mailbox. Figure 1 and Figure 2 describe the values you specify for each parameter. For example, if you want to create a mailbox and an AD domain user account named EthanW for Ethan Wilansky in the Scripters OU below the IT OU of the adatum.com domain, you'd type

Crum55.wsf /a:ad /u:EthanW/f:Ethan /l:Wilansky/c:ou=scripters,ou=it,dc=adatum,dc=com/d:adatum

and press Enter. (Although this command appears on several lines here, you would enter this command all on one line when you enter it at the command line.)

Notice that the parameter order in the example differs from the parameter order that Figure 1 and Figure 2 show. I switched the order to demonstrate that the parameters' order is irrelevant. You can arrange the parameters any way that works best for you. However, when a parameter's value contains a space, you must enclose the value in quotes (e.g., /u: "Ethan Wilansky").

The XML Advantage in CrUM55.wsf
Listing 1 contains CrUM55.wsf. One reason why CrUM55.wsf uses the XML format is to take advantage of the element. This element documents usage information that the .wsf file displays when it runs. The code at callout A in Listing 1 shows CrUM55.wsf's usage information. CrUM55.wsf calls CrUM55.vbs, which uses the ShowUsage method to display the contents of the element. Figure 1 and Figure 2 are the result. ShowUsage is a special method that WSH 5.6 includes. If you use the element and the ShowUsage method, you don't have to write extra code to provide Help information.

The element, which is the parent of the element, encapsulates one task in a .wsf file. I could have defined several jobs in this file, but for simplicity, I defined creating a user account and a mailbox as one task and, therefore, one job. The opening tag appears directly above callout A in Listing 1, and the closing tag appears near the end of Listing 1.

The element is the parent of the element and contains one or more jobs in the .wsf file. Because this .wsf file involves only one job, the element is optional. However, I recommend including it so that you get in the habit of adding this element.

The

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like