# encoding: ascii
# api: xml
# title: ScriptingAgentConfig.xml
# description: Sample ScriptingAgentConfig.xml for working with the Exchange Server 2010 Scripting Agent cmdlet extension agent.
# version: 1.0
# author: Jan Egil Ring
# license: CC0
# x-poshcode-id: 2308
# x-archived: 2016-08-30T08:19:18
# x-published: 2011-10-17T08:21:00
#
# For more details, see the following blog-post:
# http://blog.powershell.no/2010/10/17/using-cmdlet-extension-agents-to-customize-mailbox-provisioning
#
<?xml version="1.0" encoding="UTF-8" ?>
<Configuration version="1.0">
<Feature Name="MailboxProvisioningDatabase" Cmdlets="new-mailbox">
<ApiCall Name="ProvisionDefaultProperties">
#Regex switch to decide mailboxdatabase based on the user specified Name-attribute
switch -regex (($provisioningHandler.UserSpecifiedParameters["Name"]).substring(0,1))
{
"[A-F]" {$databasename = "MDB A-F"}
"[G-L]" {$databasename = "MDB G-L"}
"[M-R]" {$databasename = "MDB M-R"}
"[S-X]" {$databasename = "MDB S-X" }
"[Y-Z]" {$databasename = "MDB Y-Z" }
default {$databasename = "MDB Y-Z" }
}
#New template recipient
$user = new-object -type Microsoft.Exchange.Data.Directory.Recipient.ADUser;
#The template recipient are provided a database based on the result of the regex switch
$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";
#The template recipient are provided as an argument to a new template mailbox which will be used by the New-Mailbox cmdlet
new-object -type Microsoft.Exchange.Data.Directory.Management.Mailbox -argumentlist $user
</ApiCall>
</Feature>
</Configuration>