This is one of those questions that comes up every once in a while – How can I create an Exchange 2003 Mailbox using PowerShell? Let me first say that creating mailboxes using PowerShell is better suited for Exchange 2007 or 2010. That being said, if you are determined to get this done, it is possible to create Exchange 2003 mailboxes using PowerShell and CDOEXM, but the process is a little tricky.

You may be wondering…what is CDOEXM? CDO for Exchange Management (CDOEXM) is a COM component that provides classes and interfaces used to manage Exchange 2000 or 2003. CDOEXM gets loaded on a machine when you install the Exchange tools, and is the recommended component to use when programatically creating mailboxes in Exchange 2000/2003. Below you will find the steps I used to create an Exchange 2003 mailbox using PowerShell and CDOEXM:

Step 1: Create an Interop Assembly for CDOEXM

Those of you searching for examples may have seen references to interop.cdoexm.dll in code samples on various blogs and websites. In order to use CDOEXM in a PowerShell script, you first have to create an interop assembly using the COM Interop utility (TlbImp.exe). This will create a .NET wrapper for the CDOEXM component. The TblImp utility can be installed with the .Net Framework SDK or as part of Visual Studio. In this case, I am using Visual Studio 2008 and TblImp is located in %Program Files%\Microsoft Visual Studio 8\SDK\v2.0\Bin. The following syntax can be used to create the assembly:

.\TlbImp.exe “C:\Program Files\Exchsrvr\bin\cdoexm.dll” /out:c:\interop.cdoexm.dll

Step 2: Create a PowerShell Function

Next, I created a function based on the example in this post – I had to tweak the code to get it working in PowerShell v2. I also cheated and used the Quest AD cmdlets because it provides an easy way to grab the user and mailbox store DN based on the values of the parameters. Take a look at the code to see what I mean:

Function Add-2003Mailbox {

  begin {
    $assembly = Add-Type -Path "c:\interop.CDOEXM.dll" -PassThru
    $assembly_type = $assembly | ?{$ -eq "IMailboxStore"}
    $binding_flags = [Reflection.BindingFlags] "invokemethod,public"

  process {
    $account = [adsi]"LDAP://$(Get-QADUser $User | select -ExpandProperty DN)"
    $mailboxstoreDN = Get-QADObject -LdapFilter "(objectClass=msExchPrivateMDB)" `
    -SearchRoot (Get-QADRootDSE ).ConfigurationNamingContext |
    ?{$ -eq $MailboxStore} |
    select -ExpandProperty DN


This function will mailbox enable an existing Active Directory account using the user name and mailbox store name as parameters. Keep in mind that even though we’re importing the interop.cdoexm.dll assembly, this still needs to be run from a machine with CDOEXM installed. So, in order to use this function, you’ll need PowerShell v2, the Quest AD cmdlets and the Exchange 2003 tools installed.

Step 3: Create a Mailbox

Now that we have the function created, we are ready to add a mailbox to an existing Active Directory user. All we need to do is provide the account name and Exchange 2003 Mailbox Store name as parameters. For example, this would mailbox enable a user named testuser and create the mailbox in the “Mailbox Store (EX01)” store:

Add-2003Mailbox -User testuser -MailboxStore "Mailbox Store (EX01)"

So, that’s all there is to it. I tested all of this from a Windows Server 2003 R2 SP2 box running Exchange 2003 SP2 and PowerShell v2 – there were some quirks to work through along the way. Again, if you are looking to automate Exchange I would highly recommend upgrading to 2007/2010.