
Using the Exchange Management Shell to Create a Transport Rule
To create a new transport rule in the Exchange Management Shell, you must use variables and arrays because of the complex nature of the conditions, exceptions, and actions that are available for use with the commands.
Important: |
|---|
|
If you configure a transport rule condition or exception that uses a distribution group, you must specify a universal security group. This is required because transport rules are replicated to all Hub Transport servers in an organization and may include Hub Transport servers in remote Active Directory domains. These Active Directory domains may not have access to distribution groups that were not created as universal distribution groups.
|
Note: |
|---|
|
If you want your transport rule to apply to all e-mail messages, do not create any condition or exception variables. Instead, see "Assigning an Action to a Variable" later in this topic.
|
For more information about how transport rules are applied and how they differ when they are run on a Hub Transport server and an Edge Transport server, see Understanding How Transport Rules Are Applied in an Exchange 2007 Organization.
To work with transport rules in the Exchange Management Shell, you must be familiar with the following concepts:
For more information the Exchange Management Shell, see Using the Exchange Management Shell.
Assigning a Condition to a Variable
To select a condition for use with a transport rule, you must assign a condition to a variable. To assign a condition to a variable, you must specify the condition that you want to test against an e-mail message as a parameter of the Get-TransportRulePredicate command. For detailed information about the predicates that are available for use on Hub Transport servers and Edge Transport servers, see Transport Rule Predicates.
Use the following syntax to assign a condition to a variable:
$Condition = Get-TransportRulePredicate <Predicate Name>

To assign the Get-TransportRulePredicate command to a variable
You can specify multiple conditions for use with a single transport rule by assigning new conditions to new variables.

To create multiple conditions by assigning each new condition to a new variable
Assigning a Value to a Condition
To assign a value to a condition, find the predicate property of the condition. For detailed information about each predicate and its property or properties, and what values they accept, see Transport Rule Predicates. In Transport Rule Predicates, see the table for the server role on which you are configuring the transport rule.
Many values that are assigned to a condition must be expressed in the form of an array. In the predicate properties table in Transport Rule Predicates, you can find information about whether a predicate requires an array and the expected format of its values. The following example shows how to specify a value by using an array:
$Variable.PredicateProperty = @("<value1>", "<value2>", "<value...>")

To assign words and phrases to the Words predicate property of the SubjectContains condition
If you want to create multiple conditions to use with your transport rule, repeat this process for each condition variable.
You can also use pattern matching with conditions. Pattern matching enables you to specify a pattern that the transport rule uses to dynamically match strings in an e-mail message.
For more information about pattern matching, see Regular Expressions in Transport Rules.
Assigning Multiple Predicate Properties
Some conditions require that you assign two predicate properties. In these cases, you must also specify a value for the second predicate property. For detailed information, see the second predicate property column of the server role tables in Transport Rule Predicates for the server role on which you are configuring the transport rule.

To examine the Message-ID message header field for the value contoso.com
Assigning an Exception to a Variable
You assign exceptions to a variable just as you assign conditions to a variable. Instead of using Condition as a variable name, use Exception. As with conditions, you can also create multiple exceptions for use on a single transport rule by changing the name of the variable that is used for each exception. Exceptions use the same predicates that are described in Transport Rule Predicates.

To create multiple exceptions for use with a transport rule
As with conditions, you can also use pattern matching with exceptions. Pattern matching enables you to specify a pattern that the transport rule uses to dynamically match strings in an e-mail message.
For more information about pattern matching, see Regular Expressions in Transport Rules.
Assigning an Action to a Variable
To select an action for use with a transport rule, you must assign an action to a variable. To assign an action to a variable, you must specify the action that you want to apply to an e-mail message as a parameter of the Get-TransportRuleAction command. For a list of the actions that are available for use on Hub Transport servers and Edge Transport servers, see Transport Rule Actions. Use the following syntax to assign an action to a variable:
$Action = Get-TransportRuleAction <Action Name>

To assign the Get-TransportRuleAction command to a variable
You can specify multiple actions for use with a single transport rule by assigning new actions to new variables.

To create multiple actions by assigning each new action to a new variable
Assigning a Value to an Action
To assign a value to an action, find the action property of the action. For a list of each action property and the values it accepts, see Table 1 in Transport Rule Actions. Table 1 lists the action properties that you can use with transport rules that are configured on a Hub Transport server or an Edge Transport server.
Some action properties require that only one value be assigned to that property. Other action properties let you specify multiple values. In Table 1, in Transport Rule Actions, you can find information about whether an action requires an array and the expected format of its values.
Use the following command syntax to assign a single value to an action:
$Action.ActionProperty = <Action Value>
Use the following command syntax to assign multiple values to an action by using an array:
$Variable.ActionProperty = @("<value1>", "<value2>", "<value...>")

To assign a single value to the SclValue action property of the SetScl action

To assign multiple values to the Addresses action property of the CopyTo action
If you create multiple actions for use with your transport rule, repeat this process for each action variable.
Assigning Multiple Action Properties
Some actions require that you set two actions properties. In these cases, you must specify a value for the second action property. For detailed information, see the second action property column of the server role tables in Transport Rule Actions for the server role on which you are configuring the transport rule.

To create an action that sets a value for a specific message header field