Set-transportrule to specific email address

Arnone, Anthony 61 Reputation points
2021-06-01T14:06:13.783+00:00

I am looking to use PowerShell to add a transportrule to an individual email address, from looking online I believe this might work:

Set-TransportRule "Block Sending emails" -from ((Get-TransportRule "Block Sending emails").From += someone@mathieu.company .com)

So first question, is this doing what I am looking for and then second how do I go about removing this rule from the user?

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,383 questions
{count} votes

Accepted answer
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 30,281 Reputation points Microsoft Vendor
    2021-06-02T09:09:12.357+00:00

    Hi,

    Please try this

    $from=(Get-TransportRule "Block Sending emails").From  
    $from += "someone@company.com"  
    Set-TransportRule "Block Sending emails" -From $from  
    

    To remove it you could try this

    $from=[System.Collections.ArrayList](Get-TransportRule "Block Sending emails").From  
    $from.Remove("someone@company.com")  
    Set-TransportRule "Block Sending emails" -From $from  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful