Export (0) Print
Expand All

How to Modify Transport Rule Actions in the Exchange Management Shell

 

Applies to: Exchange Server 2007 SP3, Exchange Server 2007 SP2, Exchange Server 2007 SP1, Exchange Server 2007

Topic Last Modified: 2007-08-27

This topic explains how to use the Exchange Management Shell to modify the actions on an existing transport rule that is configured on a computer that has the Microsoft Exchange Server 2007 Hub Transport server role or the Edge Transport server role installed.

For more information about the Transport Rules agents, see Overview of Transport Rules.

Before you perform the following procedures, see How to Modify a Transport Rule, which provides important information that is required to modify transport rule actions.

To perform these procedures, the account you use must be delegated the following:

  • Exchange Organization Administrator role

To perform the following procedures on a computer that has the Edge Transport server role installed, you must log on by using an account that is a member of the local Administrators group on that computer.

For more information about permissions, delegating roles, and the rights that are required to administer Exchange 2007, see Permission Considerations.

To perform these procedures, you must be familiar with the following concepts:

For more information about the Exchange Management Shell, see Using the Exchange Management Shell.

First, you must preserve the existing actions. Assign each existing action in the action array to its own variable. Use the following command syntax to assign the action array to a variable:

$ActionArray = (Get-TransportRule "<rule name>").Actions

  1. Run the following command to assign the action array to a variable:

    $ActionArray = (Get-TransportRule "Test Rule").Actions
    
  2. Run the following command to view the number of actions in the array:

    $ActionArray.Length
    

Then assign each action in the array to its own variable. The actions are in array elements, which are numbered 0 through $ActionArray.Length - 1. Use the following syntax to assign each action array element to its own variable:

$ExistingAction<Array Element Number> = $ActionArray[<Array Element Number>]

  • Run the following commands:

    $ExistingAction0 = $ActionArray[0]
    $ExistingAction1 = $ActionArray[1]
    

Then create the new action or actions. You cannot use the actions that are already applied to the existing transport rule. Use the following syntax to assign a new action to a variable:

$NewAction = Get-TransportRuleAction <Action Name>

For a list of transport rule actions, see Transport Rule Actions.

  • Run the following command:

    $NewAction = Get-TransportRuleAction LogEvent
    

After you assign the new action to a new variable, assign a value to the action. Use the following command to assign a value to the new action:

$NewAction.<ActionProperty> = <Single Value or Array of Values>

For a list of transport rule action properties and the expected formatting of their values, see Transport Rule Actions.

  • Run the following command:

    $NewAction.LogMessage = "Transport Rule triggered"
    

After you create all the new actions, apply the actions to the existing transport rule. Use the following command syntax to modify the transport rule:

Set-TransportRule <Transport Rule Name> -Action @(<Actions>)
noteNote:
You must order the existing and new actions according to their Rank when you specify the actions in the Set-TransportRule command. Use the Get-TransportRuleAction command to view the rank of each action.

  • Run the following command:

    Set-TransportRule "Test Rule" -Action @($ExistingAction0, $ExistingAction1, $NewAction)
    

To remove an action from a transport rule, follow these steps from the section earlier in this topic:

  1. Assign the actions of a transport rule to a variable and view how many actions are in the array.

  2. Assign each action array element to its own variable, except the action that you want to remove.

  3. Modify the existing transport rule.

  1. Run the following command to assign the action array to a variable:

    $ActionArray = (Get-TransportRule "Test Rule").Actions
    
  2. Run the following command to view the number of actions in the array:

    $ActionArray.Length
    
  3. Run the following command to view the actions in the $ActionArray variable and note the array element number of the action you want to remove:

    $ActionArray
    
  4. Run the following commands to assign the actions that you want to keep to variables, omitting the array elements of the actions that you do not want to keep:

    $ExistingAction1 = $Action[1]
    ...
    
  5. Run the following command to modify the transport rule, assigning only the variables associated with the actions that you want to keep:

    Set-TransportRule "Test Rule" -Action @($ExistingAction1)
    

The procedures for modifying an action depend on whether the action accepts single or multiple values. Follow the procedure that applies to the type of action that you want to modify.

noteNote:
The following examples use transport rule actions that are available on Hub Transport servers.

To determine the type of action that you want to modify, see Transport Rule Actions.

First, assign the actions of the existing transport rule to a variable and view the array. Use the following command syntax:

$ActionArray = (Get-TransportRule "Test Rule").Actions

  1. Run the following command to assign the action array to a variable:

    $ActionArray = (Get-TransportRule "Test Rule").Actions
    
  2. Run the following command to view actions in the array:

    $ActionArray
    

Determine which action you want to modify and note its array element number. The first action in the array is at array element 0. If the action that you want to modify is the third action in the list, its array element number is 2. You must then determine the action property or properties. The action properties are always listed immediately before the line starting with Name.

After you determine the array element number, assign the new value to that action by using the following command syntax:

$ActionArray[<array element number>].<Action Property> = <Single Value>

For a list of transport rule action properties and the expected formatting of their values, see Transport Rule Actions.

  • Run the following command:

    $ActionArray[2].SclValue = "7"
    

  • Run the following command:

    Set-TransportRule "Test Rule" -Action $ActionArray
    
noteNote:
You don't have to insert the $ActionArray variable in an array because the $ActionArray variable is already an array.

First, you must assign the actions of the existing transport rule to a variable and view the array. Use the following command syntax:

$ActionArray = (Get-TransportRule "Test Rule").Actions

  1. Run the following command to assign the action array to a variable:

    $ActionArray = (Get-TransportRule "Test Rule").Actions
    
  2. Run the following command to view actions in the array:

    $ActionArray
    

Determine which action you want to modify and note its array element number. The first action in the array is at array element 0. If the action that you want to modify is the third action in the list, its array element number is 2. You must then determine the action property or properties of the action. The action's action properties are always listed immediately before the line starting with Name, as in the following example:

Addresses         : {Legal Group, Regulatory Compliance}
Name              : RedirectMessage
Rank              : 10
LinkedDisplayText : redirect the message to <a id="Addresses">addresses</a>

RejectReason       : Example Message
EnhancedStatusCode : 5.7.1
Name               : RejectMessage
Rank               : 11
LinkedDisplayText  : send <a id="RejectReason">bounce message</a> to sender with <a id ="EnhancedStatusCode">enhanced status code</a>

In this example, the first action, at array element 0, has the action property Addresses. The second action, at array element 1, has the action properties RejectReason and EnhancedStatusCode.

To add new values to an existing action, use the following command syntax:

$ActionArray[<Array Element Number>].<Action Property> += <Array of Values>

For a list of transport rule action properties and the expected formatting of their values, see Transport Rule Actions.

  • Run the following command:

    $ActionArray[0].Addresses += @((Get-DistributionGroup "Example Group 1"), (Get-DistributionGroup "Example Group 2))
    

  • Run the following command:

    Set-TransportRule "Test Rule" -Action $ActionArray
    
noteNote:
You don't have to insert the $ActionArray variable in an array because $ActionArray variable is already an array.

To remove values from an existing action, you must note the existing values and then re-enter the existing values into the action, omitting the values that you no longer want. When you perform the following procedure, the existing values are replaced with the values that you specify.

noteNote:
The following procedure works well for actions that have only a few values configured. However, for actions that have dozens, or hundreds, of values configured, this procedure is not feasible. We recommend that you use a ForEach loop when it is impractical to manually reassign values to an action.
For more information, see Using the Exchange Management Shell.

First, you must assign the actions of the existing transport rule to a variable and view the array. Use the following command syntax:

$ActionArray = (Get-TransportRule "Test Rule").Actions

  1. Run the following command to assign the action array to a variable:

    $ActionArray = (Get-TransportRule "Test Rule").Actions
    
  2. Run the following command to view actions in the array:

    $ActionArray
    

Then view the values of the action that you want to modify and replace the values of that action with the values that you want to keep. For more information about how to determine the element number and action properties of an action array, see "Adding Values to an Existing Multiple-Value Action" earlier in this topic. Use the following command syntax:

$ActionArray[<Array Element Number>]

Then replace the existing values of the action that you want to modify with the values that you want to keep. Use the following command syntax:

$ActionArray[<Array Element Number>].<Action Property> = <Array of Values>

For a list of transport rule action properties and the expected formatting of their values, see Transport Rule Predicates.

  1. Run the following command to view current values that are configured on the action:

    $ActionArray[0]
    
  2. Run the following command to replace the current values with the desired values:

    $ActionArray[0].Addresses = @((Get-Mailbox "Kim Akers"),(Get-Mailbox "Frank Lee"))
    

  • Run the following command:

    Set-TransportRule "Test Rule" -Action $ActionArray
    
    noteNote:
    You don't have to insert the $ActionArray variable in an array because $ActionArray variable is already an array.
 
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft