Tuesday, June 14, 2016

Quickly Updating Domain Based Exlusions

Hi folks,

As you well know that in Exchange 2013/16 you can now configure some new conditions about which you can read here. Among them are RecipientDomainIs and SenderDomainIs which allow you to control transport rules based on the SMTP domain of a sender and a recipient of an email. Both of these attributes are multi-value attributes and are quite easy to manipulate from EAC.

Now imagine you have transport rule which manipulates email which are perform a certiain action when email is sent to one of the domains in the list. Let's say you need the same manipulation to be done also when email is sent to people from contoso.com domain. When using PowerShell by adding and removing domains while when you type something like:
Set-TransportRule "My Transport Rule" -RecipientDomainIs contoso.com

will overwrite all the current values.

Therefore something like the code below should do a magic for you.

$RecDom = (Get-TransportRule "My Transport Rule").RecipientDomainIs
$RecDom += "contoso.com"
Set-TransportRule "My Transport Rule" -RecipientDomainIs $RecDom

All you need to do is to feed the current list of SMTP domains into a variable (let's call it $RecDom). After which we update variable with a new domain (contoso.com in our case). And finally we will update RecipientDomainIs value with the updated variable. This will preserve the current list of SMTP domains as well as add the desired domain to the list.

The similar kind of manipulation can be done with the SenderDomainIs parameter as well.


No comments:

Post a Comment