M365 Changelog: Retiring Import-TransportRuleCollection in Exchange Online PowerShell

MC672157 – The Import-TransportRuleCollection cmdlet will be retired in Exchange Online PowerShell on September 30, 2023. This means that it will no longer be supported or available for use. The following steps are our recommendation to achieve the same results.

When this will happen:

September 30, 2023

How this will affect your organization:

After the retirement date, the Import-TransportRuleCollection cmdlet will no longer be available for use in Exchange Online PowerShell.

How did Import-TransportRuleCollection cmdlet work and how to achieve the same results:

There are two actions that were performed by Import-TransportRuleCollection cmdlet:

  1. Remove existing mail flow rules (also known as transport rules)
  2. Create new mail flow rules from an XML file that was generated by the Export-TransportRuleCollection cmdlet.

You can do both actions manually in PowerShell.

Before you begin, Microsoft recommendeds backing up any existing mail flow rules by exporting them to a file:

$file = Export-TransportRuleCollection

System.IO.File::WriteAllBytes('C:/MailFlowRuleCollections/BackupRuleCollection.xml', $file.FileData)

  1. Remove all existing mail flow rules:
    Get-TransportRule | foreach { Remove-TransportRule $_.Guid -Confirm:$false }
  2. Import mail flow rules from an XML file that was generated by the Export-TransportRuleCollection cmdlet.

           The Export-TransportRuleCollection generates an XML file that contains a “commandBlock” node with a New-TransportRule command for each rule.

            To import Transport Rules from the XML file that was generated by the Export-TransportRuleCollection cmdlet, you need to iterate through all the “rule” nodes and execute the New-TransportRule cmdlet that is in the “commandBlock” node. Here’s an example of how this is done:

if ((Get-TransportRule).Count -ne 0)


Write-Host "Please remove your current mail flow rules first."



xml$xml = Get-Content "C:/TMailFlowRuleCollections/RuleCollectionToImport.xml"

$rulesToImport = $xml.SelectNodes("//rules/rule")

if ($rulesToImport.Count -eq 0)


Write-Host "There are no mail flow rules to import."



Write-Host "Importing $($rulesToImport.Count) mail flow rules."

$index = 0

foreach ($rule in $rulesToImport)



Write-Host "Importing rule '$($rule.Name)' $index/$($rulesToImport.Count)."

Invoke-Expression $($rule.version.commandBlock.InnerText) | Out-Null


What you need to do to prepare:

No action is required from admins to prepare for this change. However, Microsoft advises admins to familiarize themselves with the information provided and begin using it before the retirement date.

Additional information