Finding Transport Rule Size

Published Feb 24 2022 08:27 AM 7,499 Views

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.

Why is knowing the size of an ETR important? Because the maximum size of an individual transport rule in Exchange Online is 8KB. Although it’s not easy to reach that limit, it might happen if the rule contains too many values. If it does, you get the following error:

Rulesize01.png

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:

$ruleName = "Your ETR here"

Next, use Export-TransportRuleCollection with -Format InternalXML to export all ETRs found in AD to XML.

$file = Export-TransportRuleCollection -Format InternalXML

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:

[xml]$xml = [System.Text.Encoding]::UTF8.GetString($file.FileData)

Now you should be able to parse the XML. All rules were added, so you need to filter for the ETR you want:

$null = ($xml.SelectNodes("//rule")).Where({$_.name -notmatch "$ruleName"}) | % {$_.ParentNode.RemoveChild($_)}

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.

$xml.rules.rule.RemoveAttribute("id")

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:

$node.Length

The output is in bytes; the following example shows a rule at the limit of 8192 bytes.

Rulesize02.png

Here is the full script:

$ruleName = "Your ETR here"
$file = Export-TransportRuleCollection -Format InternalXML
[xml]$xml = [System.Text.Encoding]::UTF8.GetString($file.FileData)
$null = ($xml.SelectNodes("//rule")).Where({$_.name -notmatch "$ruleName"}) | % {$_.ParentNode.RemoveChild($_)}
$xml.rules.rule.RemoveAttribute("id")
[string]$node = $xml.rules.rule.OuterXml
$node.Length

You can also use the following cmdlets to show all ETR size descending by the length in bytes:

($xml = ([xml][System.Text.Encoding]::UTF8.GetString((Export-TransportRuleCollection -Format InternalXML).FileData))).SelectNodes("//rule").RemoveAttribute("id")
$xml.rules.rule | %{ [pscustomobject]@{Name = $_.Name; LengthInBytes = $_.OuterXml.Length} } | Sort LengthInBytes -Descending

You can use following script in Exchange Server to retrieve the value directly from the msExchTransportRuleXml attribute:

$ruleName = "Your ETR here"
$rule = Get-TransportRule -Identity $ruleName
$obj = Get-ADObject -SearchBase $rule.DistinguishedName -lDAPFilter "(CN=$ruleName)" -Properties "msExchTransportRuleXml"
$obj.msExchTransportRuleXml.Length

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.

Denis Vilaça Signorelli
Service Engineer

2 Comments
%3CLINGO-SUB%20id%3D%22lingo-sub-3212522%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20Transport%20Rule%20Size%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3212522%22%20slang%3D%22en-US%22%3E%3CP%3EGreat%20post%20thanks!%26nbsp%3B%3C%2FP%3E%3CP%3EI%20know%20inbox%20rules%20also%20have%20similar%20limits%20expressed%20in%20KB.%20I%20always%20wondered%20how%20to%20get%20inbox%20rules%20total%20size%20for%20a%20mailbox.%20I%20don't%20think%20there%20is%20an%20easy%20way%20to%20get%20that%20info.%20That%20would%20be%20a%20fantastic%20article!%20%3A)%3C%2Fimg%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3210395%22%20slang%3D%22en-US%22%3EFinding%20Transport%20Rule%20Size%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3210395%22%20slang%3D%22en-US%22%3E%3CP%3EA%20question%20we%20sometimes%20hear%20from%20Exchange%20Online%20admins%20is%20%E2%80%9CHow%20can%20I%20determine%20the%20size%20of%20an%20Exchange%20Transport%20Rule%20(ETR)%3F%E2%80%9D%20Sounds%20like%20a%20pretty%20easy%20question%2C%20but%20unfortunately%20there%20is%20no%20out%20of%20the%20box%20method%20to%20determine%20transport%20rule%20size.%20Until%20now%2C%20the%20answer%20has%20been%20elusive.%3C%2FP%3E%0A%3CP%3EWhy%20is%20knowing%20the%20size%20of%20an%20ETR%20important%3F%20Because%20the%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Foffice365%2Fservicedescriptions%2Fexchange-online-service-description%2Fexchange-online-limits%23journal-transport-and-inbox-rule-limits-across-standalone-options%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Emaximum%20size%20of%20an%20individual%20transport%20rule%20in%20Exchange%20Online%20is%208KB%3C%2FA%3E%3C%2FSPAN%3E.%20Although%20it%E2%80%99s%20not%20easy%20to%20reach%20that%20limit%2C%20it%20might%20happen%20if%20the%20rule%20contains%20too%20many%20values.%20If%20it%20does%2C%20you%20get%20the%20following%20error%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22Rulesize01.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F351052i924F2866FC48E995%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Rulesize01.png%22%20alt%3D%22Rulesize01.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EFor%20this%20reason%2C%20you%20might%20want%20to%20monitor%20the%20size%20of%20your%20rules%20and%20avoid%20being%20blocked%20unexpectedly%20if%20you%20add%20conditions.%20But%20before%20we%20start%2C%20let%E2%80%99s%20understand%20some%20basic%20concepts%20around%20Transport%20Rules.%3C%2FP%3E%0A%3CH1%20id%3D%22toc-hId--2109919120%22%20id%3D%22toc-hId--2109918436%22%20id%3D%22toc-hId--2109918436%22%20id%3D%22toc-hId--2109918436%22%20id%3D%22toc-hId--2109918436%22%3ETransport%20Rule%20Basic%20Concepts%3C%2FH1%3E%0A%3CP%3EWhen%20you%20create%20an%20ETR%2C%20Exchange%20Server%20or%20Exchange%20Online%20create%20an%20object%20in%20Active%20Directory%20(AD)%20under%20the%20CN%3DTransportVersioned%20container%20as%20an%20msExchTransportRule%20class.%20This%20object%20contains%20several%20attributes%20related%20to%20the%20rule%2C%20but%20the%20one%20that%20we%E2%80%99ll%20focus%20on%20is%20msExchTransportRuleXml.%20This%20is%20a%20string%20attribute%20in%20XML%20format%20that%20contains%20all%20the%20information%20about%20the%20rule%20(the%20name%2C%20conditions%2C%20actions%2C%20exceptions%2C%20etc.).%3C%2FP%3E%0A%3CP%3EUnderstanding%20the%20msExchTransportRuleXml%20attribute%20is%20essential%20as%20the%20Exchange%20code%20relies%20on%20the%20length%20of%20this%20attribute%20to%20check%20the%20size%20of%20rule.%20A%20very%20simple%20mechanism%2C%20don%E2%80%99t%20you%20think%3F%20And%20indeed%2C%20it%20is%20if%20msExchTransportRuleXml%20is%20accessible.%20If%20you%20run%20Exchange%20Server%2C%20you%20can%20get%20the%20size%20of%20this%20attribute%20using%20the%20Get-ADObject%20cmdlet.%20As%20you%20probably%20can%20guess%2C%20the%20Get-ADObject%20cmdlet%20won%E2%80%99t%20work%20in%20Exchange%20Online.%20But%20there%20are%20other%20options%3B%20such%20as%20a%20script!%3C%2FP%3E%0A%3CP%3EAlthough%20there%20is%20no%20way%20to%20manipulate%20msExchTransportRuleXml%20directly%20using%20Exchange%20Online%20PowerShell%2C%20there%20is%20a%20cmdlet%20that%20can%20help%20us%3A%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fpowershell%2Fmodule%2Fexchange%2Fexport-transportrulecollection%3Fview%3Dexchange-ps%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EExport-TransportRuleCollection%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH1%20id%3D%22toc-hId-377593713%22%20id%3D%22toc-hId-377594397%22%20id%3D%22toc-hId-377594397%22%20id%3D%22toc-hId-377594397%22%20id%3D%22toc-hId-377594397%22%3EUsing%20a%20Script%3C%2FH1%3E%0A%3CP%3ETo%20build%20your%20own%20script%2C%20start%20by%20assigning%20the%20ETR%20name%20you%20want%20to%20retrieve%20to%20a%20variable%3A%3C%2FP%3E%0A%3CP%20class%3D%22code%22%3E%24ruleName%20%3D%20%22Your%20ETR%20here%22%3C%2FP%3E%0A%3CP%3ENext%2C%20use%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fpowershell%2Fmodule%2Fexchange%2Fexport-transportrulecollection%3Fview%3Dexchange-ps%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EExport-TransportRuleCollection%3C%2FA%3E%3C%2FSPAN%3E%20with%20-Format%20InternalXML%20to%20export%20all%20ETRs%20found%20in%20AD%20to%20XML.%3C%2FP%3E%0A%3CP%20class%3D%22code%22%3E%24file%20%3D%20Export-TransportRuleCollection%20-Format%20InternalXML%3C%2FP%3E%0A%3CP%3EIf%20you%20check%20the%20FileData%20property%20on%20the%20XML%20file%20containing%20the%20ETR%20export%2C%20you%E2%80%99ll%20see%20measurements%20in%20bytes%2C%20which%20means%20that%20you%20need%20to%20decode%20the%20FileData%20from%20byte%20array%20to%20string%20and%20cast%20it%20to%20XMLDocument%3A%3C%2FP%3E%0A%3CP%20class%3D%22code%22%3E%5Bxml%5D%24xml%20%3D%20%5BSystem.Text.Encoding%5D%3A%3AUTF8.GetString(%24file.FileData)%3C%2FP%3E%0A%3CP%3ENow%20you%20should%20be%20able%20to%20parse%20the%20XML.%20All%20rules%20were%20added%2C%20so%20you%20need%20to%20filter%20for%20the%20ETR%20you%20want%3A%3C%2FP%3E%0A%3CP%20class%3D%22code%22%3E%24null%20%3D%20(%24xml.SelectNodes(%22%2F%2Frule%22)).Where(%7B%24_.name%20-notmatch%20%22%24ruleName%22%7D)%20%7C%20%25%20%7B%24_.ParentNode.RemoveChild(%24_)%7D%3C%2FP%3E%0A%3CP%3EAnother%20thing%20to%20clean%20up%20in%20the%20XML%20is%20the%20%E2%80%9CId%E2%80%9D%20attribute.%20The%20msExchTransportRuleXml%20string%20doesn%E2%80%99t%20have%20an%20Id%20attribute%2C%20so%20even%20though%20Export-TransportRuleCollection%20method%20adds%20it%2C%20you%20should%20remove%20it%20to%20align%20with%20msExchTransportRuleXml.%3C%2FP%3E%0A%3CP%20class%3D%22code%22%3E%24xml.rules.rule.RemoveAttribute(%22id%22)%3C%2FP%3E%0A%3CP%3EThe%20last%20thing%20to%20do%20is%20the%20conversion%20from%20XML%20to%20string%3A%3C%2FP%3E%0A%3CP%20class%3D%22code%22%3E%5Bstring%5D%24node%20%3D%20%24xml.rules.rule.OuterXml%3C%2FP%3E%0A%3CP%3EAnd%20now%2C%20you%20can%20check%20the%20length%20of%20the%20node%20variable%20to%20see%20the%20size%20of%20your%20rule%3A%3C%2FP%3E%0A%3CP%20class%3D%22code%22%3E%24node.Length%3C%2FP%3E%0A%3CP%3EThe%20output%20is%20in%20bytes%3B%20the%20following%20example%20shows%20a%20rule%20at%20the%20limit%20of%208192%20bytes.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22Rulesize02.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F351053iEC862766EB99F25F%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Rulesize02.png%22%20alt%3D%22Rulesize02.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EHere%20is%20the%20full%20script%3A%3C%2FP%3E%0A%3CP%20class%3D%22code%22%3E%24ruleName%20%3D%20%22Your%20ETR%20here%22%3CBR%20%2F%3E%24file%20%3D%20Export-TransportRuleCollection%20-Format%20InternalXML%3CBR%20%2F%3E%5Bxml%5D%24xml%20%3D%20%5BSystem.Text.Encoding%5D%3A%3AUTF8.GetString(%24file.FileData)%3CBR%20%2F%3E%24null%20%3D%20(%24xml.SelectNodes(%22%2F%2Frule%22)).Where(%7B%24_.name%20-notmatch%20%22%24ruleName%22%7D)%20%7C%20%25%20%7B%24_.ParentNode.RemoveChild(%24_)%7D%3CBR%20%2F%3E%24xml.rules.rule.RemoveAttribute(%22id%22)%3CBR%20%2F%3E%5Bstring%5D%24node%20%3D%20%24xml.rules.rule.OuterXml%3CBR%20%2F%3E%24node.Length%3C%2FP%3E%0A%3CP%3EYou%20can%20also%20use%20the%20following%20cmdlets%20to%20show%20all%20ETR%20size%20descending%20by%20the%20length%20in%20bytes%3A%3C%2FP%3E%0A%3CP%20class%3D%22code%22%3E(%24xml%20%3D%20(%5Bxml%5D%5BSystem.Text.Encoding%5D%3A%3AUTF8.GetString((Export-TransportRuleCollection%20-Format%20InternalXML).FileData))).SelectNodes(%22%2F%2Frule%22).RemoveAttribute(%22id%22)%3CBR%20%2F%3E%24xml.rules.rule%20%7C%20%25%7B%20%5Bpscustomobject%5D%40%7BName%20%3D%20%24_.Name%3B%20LengthInBytes%20%3D%20%24_.OuterXml.Length%7D%20%7D%20%7C%20Sort%20LengthInBytes%20-Descending%3C%2FP%3E%0A%3CP%3EYou%20can%20use%20following%20script%20in%20Exchange%20Server%20to%20retrieve%20the%20value%20directly%20from%20the%20msExchTransportRuleXml%20attribute%3A%3C%2FP%3E%0A%3CP%20class%3D%22code%22%3E%24ruleName%20%3D%20%22Your%20ETR%20here%22%3CBR%20%2F%3E%24rule%20%3D%20Get-TransportRule%20-Identity%20%24ruleName%3CBR%20%2F%3E%24obj%20%3D%20Get-ADObject%20-SearchBase%20%24rule.DistinguishedName%20-lDAPFilter%20%22(CN%3D%24ruleName)%22%20-Properties%20%22msExchTransportRuleXml%22%3CBR%20%2F%3E%24obj.msExchTransportRuleXml.Length%3C%2FP%3E%0A%3CP%3ERemember%20that%20the%20limit%20is%20not%20adjustable%20in%20Exchange%20Online.%20If%20you%20have%20large%20ETRs%2C%20we%20encourage%20you%20to%20check%20their%20size%20and%20reduce%20their%20length%20as%20much%20as%20possible%2C%20and%20to%20remove%20ETRs%20after%20they%20are%20no%20longer%20needed.%20These%20actions%20might%20help%20reduce%20your%20mail%20flow%20latency.%3C%2FP%3E%0A%3CP%3EWe%20hope%20that%20these%20details%20on%20how%20to%20retrieve%20the%20size%20of%20an%20ETR%20improve%20your%20Exchange%20Online%20and%20Exchange%20Server%20experience.%20Feel%20free%20to%20use%20the%20Comments%20section%20to%20ask%20questions%20or%20provide%20suggestions!%3C%2FP%3E%0A%3CP%3EThanks%20to%20Arindam%20Thokder%2C%20Alex%20Hudish%2C%20Keith%20Schottland%20and%20Nino%20Bilic%20for%20their%20review%20of%20this%20post.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22author%22%3EDenis%20Vila%C3%A7a%20Signorelli%3C%2FSPAN%3E%3CBR%20%2F%3EService%20Engineer%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-3210395%22%20slang%3D%22en-US%22%3E%3CP%3EA%20question%20we%20sometimes%20hear%20from%20Exchange%20Online%20admins%20is%20%E2%80%9CHow%20can%20I%20determine%20the%20size%20of%20an%20Exchange%20Transport%20Rule%20(ETR)%3F%E2%80%9D%20Read%20on%20to%20find%20out!%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3210395%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExchange%20Online%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOn%20premises%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ETips%20'n%20Tricks%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Etransport%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3214207%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20Transport%20Rule%20Size%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3214207%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F809057%22%20target%3D%22_blank%22%3E%40momurray%3C%2FA%3E%26nbsp%3BThank%20you%20for%20your%20feedback!%20You%E2%80%99re%20right%2C%20inbox%20rules%20are%20limited%20to%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fexchange%2Fclients-and-mobile-in-exchange-online%2Foutlook-on-the-web%2Fincrease-the-space-used-by-inbox-rules%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E256%20KB%20total%20for%20all%20rules%3C%2FA%3E%2C%20but%20the%20difference%20here%20is%20where%20it%20is%20stored%2C%20while%20ETR%20are%20stored%20in%20AD%20the%20Inbox%20Rules%20are%20stored%20in%20the%20user%E2%80%99s%20mailbox%20as%20MAPI%20property.%20For%20that%20reason%2C%20it%E2%80%99s%20quite%20complicated%20to%20retrieve%20the%20rule%20size%2C%20but%20it%20should%20be%20possible%20through%20MFCMAPI%20to%20find%20the%20total%20rules'%20size.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20Inbox%20folder%20there%20is%20a%20property%20called%200x3fff0003%20(PR_Rules_Size).%20That%20should%20represent%20the%20inbox%20rule%20total%20size.%20I%E2%80%99m%20not%20sure%20if%20this%20property%20is%20updated%20when%20you%20update%20an%20existing%20rule%2C%20but%20I%E2%80%99m%20sure%20that%20it%E2%80%99s%20updated%20when%20you%20create%20a%20new%20one.%20If%20you%20want%20to%20test%20it%2C%20just%20reduce%20the%20rule%20quota%20to%20the%20minimum%20allowed%20(32KB)%20and%20create%20many%20rules%20monitoring%20the%20PR_Rules_Size%20property.%20It%20should%20block%20you%20as%20soon%20as%20you%20reach%2032%2C768KB%3C%2FP%3E%3C%2FLINGO-BODY%3E
Co-Authors
Version history
Last update:
‎Feb 25 2022 07:49 AM
Updated by: