Editing an Exchange Online Mail Flow rule

28 Mar

I needed to be able to update a given mail flow rule in Exchange Online.

The current rule, “If the recipient’s address includes these words then do the following, reject the message with the explanation…”

I wanted to add an email address to this list if it didn’t already exist, so here’s the Powershell I came up with:


$list = new-object collections.arraylist
$list += Get-TransportRule "Mail Flow Rule Name" | select -expand RecipientAddressContainsWords

#check it's not already in the list
if(!($list -contains $emailaddress)){
    $list += $emailaddress 
    Set-TransportRule -Identity "Mail Flow Rule Name" -RecipientAddressContainsWords $list
     #write-host "already in the list"