A question we sometimes hear from Exchange Online admins is “How can I determine the size of an Exchange Transport Rule (ETR)?” Sounds like a pretty easy question, but unfortunately there is no out of the box method to determine transport rule size. Until now, the answer has been elusive.
For this reason, you might want to monitor the size of your rules and avoid being blocked unexpectedly if you add conditions. But before we start, let’s understand some basic concepts around Transport Rules.
Transport Rule Basic Concepts
When you create an ETR, Exchange Server or Exchange Online create an object in Active Directory (AD) under the CN=TransportVersioned container as an msExchTransportRule class. This object contains several attributes related to the rule, but the one that we’ll focus on is msExchTransportRuleXml. This is a string attribute in XML format that contains all the information about the rule (the name, conditions, actions, exceptions, etc.).
Understanding the msExchTransportRuleXml attribute is essential as the Exchange code relies on the length of this attribute to check the size of rule. A very simple mechanism, don’t you think? And indeed, it is if msExchTransportRuleXml is accessible. If you run Exchange Server, you can get the size of this attribute using the Get-ADObject cmdlet. As you probably can guess, the Get-ADObject cmdlet won’t work in Exchange Online. But there are other options; such as a script!
Although there is no way to manipulate msExchTransportRuleXml directly using Exchange Online PowerShell, there is a cmdlet that can help us: Export-TransportRuleCollection
Using a Script
To build your own script, start by assigning the ETR name you want to retrieve to a variable:
If you check the FileData property on the XML file containing the ETR export, you’ll see measurements in bytes, which means that you need to decode the FileData from byte array to string and cast it to XMLDocument:
Another thing to clean up in the XML is the “Id” attribute. The msExchTransportRuleXml string doesn’t have an Id attribute, so even though Export-TransportRuleCollection method adds it, you should remove it to align with msExchTransportRuleXml.
The last thing to do is the conversion from XML to string:
[string]$node = $xml.rules.rule.OuterXml
And now, you can check the length of the node variable to see the size of your rule:
The output is in bytes; the following example shows a rule at the limit of 8192 bytes.
Remember that the limit is not adjustable in Exchange Online. If you have large ETRs, we encourage you to check their size and reduce their length as much as possible, and to remove ETRs after they are no longer needed. These actions might help reduce your mail flow latency.
We hope that these details on how to retrieve the size of an ETR improve your Exchange Online and Exchange Server experience. Feel free to use the Comments section to ask questions or provide suggestions!
Thanks to Arindam Thokder, Alex Hudish, Keith Schottland and Nino Bilic for their review of this post.