none
automation of transport rules creation - check message header fields

    Question

  • hi everybody,

    i am trying to create another transport rule on an exchange server 2007 in powershell.

    this rule is supposed to check the mail header for certain texts. in that case it should forward

    the message as bcc. it is part of a bigger script to automate the creation of project mailboxes.

    $short = "test_02"
    $shortCollector = "test_02.collector"
    
      #create transport rule - >replyTo<
    
      $Condition1 = Get-TransportRulePredicate HeaderContains
      $mywords = @($short + "@mycompany")
      $mywords = $mywords + "cn=$short"
     
      $Condition1.messageHeader = @($mywords)                                                               
      $Action1 = Get-TransportRuleAction BlindCopyTo                                                      
      $ADOCollector = get-mailbox $shortCollector | select -expand userprincipalname                       
      $Action1.Addresses = @(get-mailbox $shortCollector)                                                  
      $RULE_name = $short + " out(replyTo)"      
      New-TransportRule -name $RULE_name -Condition @($Condition1)  -Action @($Action1)   


    it does not work as intended as i get another error like

    ...Cannot convert the "System.Object[]" value of type "System.Object[]" to type "Microsoft.Exchange.MessagingPolicies.Rules.Tasks.HeaderName".

    any ideas how i can convert correctly?

    thank you - best regards

    marc

    • Moved by Bill_Stewart Thursday, January 21, 2016 11:06 PM Move to more appropriate forum
    Monday, January 18, 2016 5:04 PM

All replies

  • Hi,

    Could you confirm are you trying with EXchange management shell. Since above command only works there.


    Regards, Krselva. Please remember to mark the replies as answers if its helps you, and unmark the answers if it is not help you.

    Thursday, January 21, 2016 11:03 PM
  • jep - confirmed.

    this is the third rule i would like to create.

    the first two work fine ... with a construction you can see in my other post.

    (sorry - no links accepted here so far.  : /  )

    best regards

    marc


    • Edited by SHA_mhz Friday, January 22, 2016 8:32 AM
    Friday, January 22, 2016 8:31 AM
  • Hi,

    According to your description, I understand that the issue is related to script. As this forum focuses on some general discussion about Exchange.

    I suggest we can ask a question in Microsoft Exchange Development forum to get more help :

    https://social.technet.microsoft.com/Forums/exchange/en-US/home?forum=exchangesvrdevelopment 

    Thank you for understanding.

    Regards,

    David 

    Friday, January 22, 2016 9:56 AM
    Moderator
  • understood - thanks
    Friday, January 22, 2016 12:02 PM