A new feature in Exchange 2007 is Transport rules this rules can be added in two ways, via the Exchange Management Console or via the Exchange Management Shell.

The transport rules will be created on the Hub transport server. The transport rules will be executed as follows:

When you choose to create the rules via the Exchange Management Shell you will see you will pass those steps.

Besides the parameters you can assign a priority to each Transport Rule. The priority start with 0, this rule has the highest priority. When a mail matches multiple rules all the rules will be applied to the mail, the priority will be used to make the decision in which order they will be applied. When you have created a rule you can adjust it very easy.

First we are going to create a Transport Rule via the Exchange Management Console. You have to start the Exchange Management Console for this, next click on Organizational Configuration, Hub Transport and select the tab Transport Rules.

Now click somewhere in the white space in the center of the screen and choose the option New Transport Rule, you can also do this on the right side of the screen. You will get the following screen:

Fill in the fields that are displayed, Name is the name you want to give to the Transport Rule, Description is a short description of the rules. The checkmark before Enable Rule is enabled by default, when you don’t want to use the rule immediately uncheck it, click on next.

First we will select the Conditions, this are the conditions that a message has to have. This can be for example: all mail to external users

The next step will be the Rules that are applied to the mail. In this case we will add a disclaimer to the e-mail.

You can see in the flowchart that we only need the define the Exceptions. In this case we don’t want to add exceptions and click on next

Before the rule is created you will get a small summary of the parameters we defined. Click on New to create the Transport Rule.

When you get the same screen as above the rule is created successfully and a disclaimer is added to all messages send to external users.

Now we created a Transport Rule via the Exchange Management Console it’s time to create one via Powershell.

We will create a rule which blocks e-mails with the word Finance in the body or subject except when the mail is send from Klaas Vaak.

Normally you get give the Powershell command directly, but with a Transport Rule this is not the case. First we will define the values for the conditions, rules and exceptionsand will use them in the Powershell command.

Below the script what what creates the Transport Rule:


$Condition = Get-TransportRulePredicate SubjectOrBodyContains
$Condition.Words = @("Finance")
$Exception = Get-TransportRulePredicate From
$Exception.Addresses = @((Get-Mailbox "Klaas.Vaak"))
$Action = Get-TransportRuleAction RejectMessage
$Action.RejectReason = "E-mail messages sent from departments except the Finance department are prohibited."

New-TransportRule -name "Block e-mail messages with the word Finance" -Condition @($Condition) -Exception @($Exception) -Action @($Action)

The same as with the wizard the script will be separated in logical steps.

With $Condition we define the conditions which a mail should meet. You can do this by specifying the command Get-TransportRulePredicate followed by , in this case SubjectOrBodyContains.

The next step we will do is assign a value for the condition, we can those this with the parameter $Condition.Words. We will give the value after the - sign.

The next step is to define the exception, this will be done by the parameters $Exception and $Exception.Addresses. With this we will tell Exchange to use the command Get-TransportRulePredicate From to get the value from the from field and assign the value to $Exception.Addresses.

The last parameter we define is the action that needs to be executed when a mail matches all requirements. This is done by the parameters $Action and $Action.RejectReason, in this case we will send a message back to the sender with the following text E-mail messages sent from departments except the Finance department are prohibited.

Now we defined all parameters we can use the New-TransportRule to create the rule. The only extra parameter we need is name which defines the name of the rule. When we don’t want to rule to be active after creation we need to add the parameter Enabled $false. The new rules will be assigned the lowest priority, can you change this by assigning the Priority parameter a numeric value.

I saved the script myself and executed it, the screen below shows the result:

The links below will direct you to the pages on Technet about the two commands:

New-TransportRule open

Get-TransportRulePredicate open


Comments


Johan Veldhuis