There have been many times in class when students have asked me if there is a way to change default settings in Exchange 2010 when perform task such as creating users. If you had asked me two weeks ago, my answer would have been: “Nope. You’ll need to modify those users after you create them.” Turns out I was wrong.
Exchange 2010 SP1 includes a component called the Scripting Agent. The Scripting Agent lets you define scripts that run when specific cmdlets, such as New-Mailbox, are used. Since the Exchange Management Console (EMC) runs cmdlets in the background, this will apply there too.
First you need to enable the Scripting Agent:
Enable-CmdletExtensionAgent “Scripting Agent”
Next, you need to create an XML file that defines the scripts to be run and for which cmdlets. The file must be named ScriptingAgentConfig.xml and located in C:\Program Files\Microsoft\Exchange\v14\Bin\CmdletExtensionAgents. I’ll post some examples later. In this post I will limit myself to describing generally what it can do.
Each time a cmdlet is used, the ScriptingAgentConfig.xml file is checked to see whether there is a script defined for the cmdlet. If there is a script defined for the cmdlet, it is executed. There are four ways a script can be run. The documentation refers to these ways as APIs.
- ProvisionDefaultProperties. This is exactly what you think it is. It lets you define default values for cmdlets parameters. For example, you could specify a default OU when creating new users. If a user running the cmdlet provides values, they override the defaults that you provide with this API.
- UpdateAffectedIConfigurable. Instead of providing defaults, this will overwrite values provided by the user running the cmdlet.
- Validate. This API is called just before the cmdlet writes data. The intent of this is to validate data that is being written before it is actually written. Your script provides the validation. If the script runs without errors, then the cmdlet proceeds to write data. Otherwise, your script needs to generate the error if the conditions you specify are not met. For example, you could verify that a valid database has been specified for a new mailbox to prevent it from being randomly assigned to a database.
- OnComplete. This API is called after the cmdlet is complete. This provides you with an opportunity to modify setting related to the original cmdlet, but not part of the original cmdlet. For example, after creating a new mailbox, you could set calendar settings that are not possible with the New-Mailbox cmdlet.
After you create ScriptingAgentConfig.xml, you need to copy it to all of your Exchange 2010 SP1 servers.
Microsoft provides some very limited documentation here: http://technet.microsoft.com/en-us/library/dd297951.aspx