Using Cmdlet Extension Agents to customize mailbox provisioning in Exchange Server 2010

Exchange Server 2010 introduced a new feature for automatically assigning a database while provisioning mailboxes, which uses the Mailbox Resources Management cmdlet extension agent. This feature are demonstrated and described in further detail in this blog post by Mike Pfeiffer.

While this new feature is a great enhancement to Exchange Server, it`s actually possible to customize it further by using another cmdlet extension agent named Scripting Agent.

There are several common ways to distribute mailboxes to databases:

  • Alphabetically
  • Per location
  • Per department
  • Random

My example will focus on using the alphabetically approach to distribute the mailboxes. I`ve re-used the regular expression switch I wrote in this blog post.

Before we proceed, you might want to read this blog post by Pat Richard on how the Scripting Agent work, as well as reading up on Cmdlet Extension Agents on the Exchange Server TechCenter on Microsoft TechNet.

1. Create a file named ScriptingAgentConfig.xml and save it to the CmdletExtensionAgents-folder which by default are C:\Program Files\Microsoft\Exchange Server\V14\Bin\CmdletExtensionAgents. Here is my sample ScriptingAgentConfig.xml:

   1: <?xml version="1.0" encoding="UTF-8" ?>
   2: <Configuration version="1.0">
   3:  
   4: <Feature Name="MailboxProvisioningDatabase" Cmdlets="new-mailbox">
   5:   <ApiCall Name="ProvisionDefaultProperties">
   6:  
   7: #Regex switch to decide mailboxdatabase based on the user specified Name-attribute
   8: switch -regex (($provisioningHandler.UserSpecifiedParameters["Name"]).substring(0,1)) 
   9:     { 
  10:        "[A-F]" {$databasename = "MDB A-F"} 
  11:        "[G-L]" {$databasename = "MDB G-L"} 
  12:        "[M-R]" {$databasename = "MDB M-R"} 
  13:        "[S-X]" {$databasename = "MDB S-X" } 
  14:        "[Y-Z]" {$databasename = "MDB Y-Z" } 
  15:         default {$databasename = "MDB Y-Z" }
  16:     }
  17:  
  18:  
  19: #New template recipient
  20: $user = new-object -type Microsoft.Exchange.Data.Directory.Recipient.ADUser;
  21:  
  22: #The template recipient are provided a database based on the result of the regex switch
  23: $user.database = "CN=$databasename,CN=Databases,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN="Exchange organization name",CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=domain,DC=local";
  24:  
  25: #The template recipient are provided as an argument to a new template mailbox which will be used by the New-Mailbox cmdlet
  26: new-object -type Microsoft.Exchange.Data.Directory.Management.Mailbox -argumentlist $user
  27:  
  28:   </ApiCall>
  29:  </Feature>
  30:  
  31: </Configuration>

You will need to customize the names of the databases, as well as the domain name and the Exchange organization name in the $user.database property. Then you would need to copy the ScriptingAgentConfig.xml to the CmdletExtensionAgents-folder on all Exchange 2010 servers in your organization.

2. From the Exchange Management Shell, run Enable-CmdletExtensionAgent "Scripting Agent". This will enable the Scripting Agent, which will use the ScriptingAgentConfig.xml file we created.

3. From the Exchange Management Shell, run Disable-CmdletExtensionAgent "Mailbox Resources Management Agent". The Mailbox Resources Management Agent must be disabled when we want to assign the database for the new mailbox using the Scripting Agent, else the Mailbox Resources Management Agent will take precedence. Alternatively we could have changed the priority of the Scripting Agent.

When the above configuration are in place, it`s time to test the new configuration, which of course should be done in a lab environment prior to putting it to production.

From the Exchange Management Console, create a new mailbox and be sure to not select “Specify the mailbox database rather than using a database automatically selected”:

clip_image002

Alternatively, if using the New-Mailbox cmdlet from the Exchange Management Shell, do not specify the “-Database” parameter.

When the test mailbox are created, verify that the database the new mailbox was assigned to is the expected one. For troubleshooting, I would recommend you to use the “–Verbose” parameter on the New-Mailbox cmdlet.

You can use the very same technique to customize database selection based on i.e. the per department approach, by accessing other properties from $provisioningHandler.UserSpecifiedParameters

Comments

No Comments