You may not see it in every organization but in a lot of organizations Outlook rules are used to automate some tasks such as: moving item to another folder, auto reply on messages, etc.

In this blog we will have a look at how to provision Outlook rules for a user so they won’t have to create them. But first have a look at the rules. As you may know you can configure both server and client side rules in Outlook. But what’s the difference between them?

  • Server side rules: are executed at the server side and so they are always running;
  • Client side rules: are execute at the client side and will only work when Outlook or OWA is running;

Most of the rules you can configure are client side rules and only a few of them are server side rules. One example of a server side rule is auto replying with a message on a new arrived e-mail.

To provision Outlook rules you can use the New-InboxRule cmdlet this cmdlet will give you the ability to create inbox rules for every user. So let’s have a look at an example.

New-InboxRule ‘Spam Summary’ -Mailbox johan -From antispam@domain.com -SubjectContainsWord “Spam Summary“ -MoveToFolder ’ johan:\ Spam Summary’

The rule above will be applied to all messages which are sent to my mailbox and are sent from antispam@domain.com and have as subject Spam Summary. The rule will move the specific message to the folder Spam Summary. One remark must be made about the folder. The folder must exist if not you will get a warning.

So wouldn’t it be nice to automate the complete process when a new mailbox is created? If this is what you want cmdlet extensions are the answer. With cmdlet extensions you can extend cmdlets by executing additional cmdlets after the first cmdlet has been executed.

In this example we would only like to create the new folder and the Outlook rule after a new mailbox is created. So the cmdlet which needs to be extended is New-Mailbox.

The first step in the process will be to modify the ScriptingAgentConfig.xml.sample. This file can be found here: \V14\Bin\CmdletExtensionAgents. First make a backup of the original XML before making any changes. Once the backup is rename the file and remove the .sample extension and open it in an editor, for example Notepad.


if($succeeded) {
  
$newmailbox = $provisioningHandler.UserSpecifiedParameters['Name&']
  
$newfolder= $newmailbox + _’__:\Spam Summary__’___
  
New-MailboxFolder -Parent $newmailbox -Name _’__Spam Summary__’_
  
New-InboxRule ’Spam Summary’ -Mailbox $newmailbox -From antispam@domain.com
  
SubjectContainsWord ’Spam Summary’ -MoveToFolder $newfolder }

We are using two parameters:

  • $newmailbox: contains the name of the created mailbox
  • $newfolder: the name of the folder we want to create in the mailbox

After the parameters have been defined we will first create the new folder using the New-MailboxFolder cmdlet and then use create the new rule using New-InboxRule cmdlet.

Now save this file and copy it to each Exchange server in your environment. The next step is to enable the scripting agent. If you don’t do it the script simply won’t be executed.

To enable the scripting agent open the Exchange Management Shell (EMS) and run the following cmdlet:

Enable-CmdletExtensionAgent 'Scripting Agent'

Repeat this step on every Exchange server in your environment.

Now we configured everything it’s time to see if it really works. Create a new mailbox via either the Exchange Management Console or Shell. After the mailbox is created verify if a new folder and rule are created successfully by logging into OWA or by using Outlook.

So let’s verify if it really works. In this example we just created a user called provisioned_user:

New-Mailbox -name provisioned\_user -alias provisioned\_user -UserPrincipalName provisioned_user@corp.local

When running the cmdlet with the –verbose parameter you will see that the Cmdlet Extension Agent is executed after the mailbox has been created:

Now the mailbox has been created let’s verify if the new folder and inbox rule have been created. We will use OWA to verify if both have been created. When logging in to OWA you will see that the folder has been created:

When opening the Exchange Control Panel (ECP) and select the Organize E-mail option in the left menu you will see that an inbox rule has been created:

So as you can see you can provision the anti-spam folder and rule for new mailboxes using the cmdlet extensions. Besides doing this kind of things several other options can be configured using this option. Some examples are:

  • Disable POP3
  • Disable IMAP
  • Set the Regional Configuration/Language

For more information you can have a look at the following pages:

  • Using Cmdlet Extension Agents to cause automatic events to occur in Exchange 2010 – life just got simpler!: open
  • Cmdlet Extension Agents Part 1: Automatic archive creation: open

Comments


Johan Veldhuis