Cmdlet extension agents are new components in Exchange 2010 that are called by Exchange 2010 cmdlets, when they are run. It is used to extend the functionality of Exchange 2010 cmdlets by running a script or set of code after the Exchange cmdlet has run. For example, you can run a set of configurations after a new mailbox has been created, basically calling the scripting agent to run a code after the New-Mailbox cmdlet completes. Scripting agent is one of the seven cmdlet extension agents available in Exchange 2010 and is the one that is disabled by default.
Get-CmdletExtensionAgent will list all the seven agents. Run Get-CmdletExtensionAgent | ft name, priority, enabled –wrap –autosize to get a refined output.
I looked at the scripting agent as one of my client asked me ways to automate things to a certain extend. I will explain the process of using the scripting agent based on what I had been asked. My client wanted to make sure that all newly created mailboxes had the following configurations, without manually setting each.
- POP, IMAP, ActiveSync is disabled
- Outlook Anywhere is disabled
- Single Item Recovery is enabled
- Fields like Country, City, Street Address, Company in the user properties needs to be filled in automatically.
- Block users from using Outlook in online mode
- Set the company OWA Mailbox Policy
Scripting agent can be used to do what my client wanted and I set it up for them. The scripting agent, when enabled, looks for a file named “ScriptingAgentConfig.xml” within the BinCmdletExtensionAgents. By default, a “ScriptingAgentConfig.xml.sample” file exists in the same location which gives an idea of the code that needs to go in the xml file. Open the sample file using notepad and understand the basic syntax the xml file needs.
Below is the basic syntax you need for the config xml file, irrespective of what you are trying to achieve. Pat Richard’s post helped me with the syntax.
if($succeeded)
{ PowerShell cmdlets }
Below is the code that I used to achieve what my client wanted.
if($succeeded)
{
$mailbox = $provisioningHandler.UserSpecifiedParameters["Alias"]
Set-CASMailbox $mailbox -ImapEnabled $false -POPEnabled $false –ActiveSyncEnabled $false –OWAMailboxPolicy "HEW OWA Policy” –MAPIBlockOutlookRpcHTTP $true –MAPIBlockOutlookNonCachedMode $true
Set-User -City ‘London’ -CountryOrRegion ‘United Kingdom’ -Company ‘How Exchange Works’ -Identity $mailbox
Set-Mailbox $mailbox -SingleItemRecoveryEnabled $true
}
The line
I copied the entire code below to notepad and saved it as ScriptingAgentConfig.xml inside BinCmdletExtensionAgents folder.
Next step is to enable the scripting agent. The agent should only be enabled once the ScriptingAgentConfig.xml is in place. Otherwise, all Exchange cmdlets except the “Get-noun” will throw errors. Run Enable-CmdletExtensionAgent “Scripting Agent” to enable the agent.
Time to test! I created a test mailbox and the scripting agent configured all the options my client wanted.
Now that you understand the power of scripting agent, you can automate tasks to make your life easier ![]()







Follow Me