none
New-TransportRule with multiple predicates

    Question

  • Hello,

    Is it possible to create a transport rule with multiple predicates using Powershell?

    For example, I would like to create a rule that will apply to messages either send by a group or sent to another.

    Moreover, I would like to do the same thing with actions, first apply an action to the message and then one more.

    Regards,

    Chris

    Saturday, May 7, 2016 12:44 PM

Answers

  • Hello David,

    You are right, there are some actions that have to be the only action on a rule, such as "Delete Message". There are rules like the one above on my Exchange with those two actions but I believe that the have been carried from a previous version of Exchange where it was allowed.

    I managed to get very close to what I'm trying to do using variables for the "From" and "SentTo" parameters. Here's the commands I used:

    $senders = @( 'address1@domain1.com', 'address2@domain2.com' ) $recipients = @ (
    'address3@mydomain.com',
    'address4@mydomain.com'
    )

    New-TransportRule -Name 'Test Rule' ` -Comments 'My Test Rule' ` -Priority '29' ` -Enabled $true ` -From $senders ` -SentTo $recipients ` -RedirectMessageTo 'SPAM@mydomain.com'

    This rule will apply to messages sent from any sender in the "senders" variable to any recipient in the "recipients" variable. Be very careful not to add to many senders and/or recipients, since this will have a performance affect on your Hub Transport servers.

    Thank you for your help,

    Chris


    Friday, May 13, 2016 6:23 PM

All replies

  • Everything you can do with the UI, you can do with PowerShell as well. For example:

    New-TransportRule -AnyOfToCcHeader group@domain.com -FromMemberOf anothergroup@domain.com -Name test -SetAuditSeverity Low -SetSCL -1

    The rule will act on any message sent to group@domain.com from a member of anothergroup@domain.com and will do two actions. You can use the "show command logging" functionality in the EAC to get the exact PowerShell syntax for the rule you need.

    Saturday, May 7, 2016 6:11 PM
  • Well, this is not what I'm looking for... It requires distribution groups and does not apply to senders external to the organization.

    Thank you for the logging suggestion, I'll try to create a rule and get the commands that way.

    Saturday, May 7, 2016 6:33 PM
  • Um, it's an example? How can we possibly know that you want "senders external to the organization" if you haven't even mentioned it in the original post?
    Sunday, May 8, 2016 6:38 AM
  • I do not expect anyone who reads the first post to completely understand the question, this is a discussion and I am more than happy to clarify any part of it.

    The question in the first post is about multiple predicates and actions on a rule. This has nothing to do with the recipients and senders being external or not. Your suggestion to use distribution groups is a workaround and not a solution.

    Below is the definition of a rule that I would like to create:

    <rule name="Rule" comments="Test Rule">
     <version requiredMinVersion="14.0.0.0">
      <fork>
       <recipient address="CRM_1@myorganisation.com" />
       <recipient address="CRM_2@myorganisation.com" />
      </fork>
      <condition>
       <and>
        <true />
        <contains property="Message.From">
         <value>user1@externalorganization1.com</value>
         <value>user2@externalorganization2.com</value>
        </contains>
        <not>
         <or>
          <contains property="Message.From">
           <value>user@externalorganization3.com</value>
           <value>user@externalorganization4.com</value>
          </contains>
         </or>
        </not>
       </and>
      </condition>
      <action name="AddEnvelopeRecipient">
       <argument value="SPAM_Mailbox@myorganisation.com" />
      </action>
      <action name="DeleteMessage" />
     </version>
    </rule>

    Christos Polydorou

    Sunday, May 8, 2016 12:25 PM
  • Hi,

    Based on my knowledge,some action must be the only action in a rule. If there is more than one action in this rule,the rule will fail to create.

    https://technet.microsoft.com/en-us/library/jj919237(v=exchg.150).aspx

    Please post the detailed error message if you can't create the rule.

    Regards,

    David 


    Wednesday, May 11, 2016 7:40 AM
    Moderator
  • Hello David,

    You are right, there are some actions that have to be the only action on a rule, such as "Delete Message". There are rules like the one above on my Exchange with those two actions but I believe that the have been carried from a previous version of Exchange where it was allowed.

    I managed to get very close to what I'm trying to do using variables for the "From" and "SentTo" parameters. Here's the commands I used:

    $senders = @( 'address1@domain1.com', 'address2@domain2.com' ) $recipients = @ (
    'address3@mydomain.com',
    'address4@mydomain.com'
    )

    New-TransportRule -Name 'Test Rule' ` -Comments 'My Test Rule' ` -Priority '29' ` -Enabled $true ` -From $senders ` -SentTo $recipients ` -RedirectMessageTo 'SPAM@mydomain.com'

    This rule will apply to messages sent from any sender in the "senders" variable to any recipient in the "recipients" variable. Be very careful not to add to many senders and/or recipients, since this will have a performance affect on your Hub Transport servers.

    Thank you for your help,

    Chris


    Friday, May 13, 2016 6:23 PM