Retiring Import-TransportRuleCollection in Exchange Online PowerShell

  • Home |
  • Retiring Import-TransportRuleCollection in Exchange Online PowerShell
Microsoft Exchange Curtain Reveal Tech Bulletin Header

MC672157 · Exchange Online, SharePoint Development, Microsoft 365 Experts

From Microsoft Corporation
Technical Bulletin MC672157 · Published Aug 31, 2023

Message Summary

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, we recommended 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."

return

}

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."

return

}

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

$index = 0

foreach ($rule in $rulesToImport)

{

$index++

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, we advise admins to familiarize themselves with the information provided and begin using it before the retirement date.

Additional information

Recent Comments

No comments to show.

Recent Posts

Microsoft 365 Curtain Reveal Tech Bulletin Header
New Outlook for Windows: Auto-reading emails with Microsoft Windows Narrator
October 14, 2024
Microsoft 365 Curtain Reveal Tech Bulletin Header
(Updated) Microsoft Purview: Minor encrypted message portal design updates, URL to remain the same
October 14, 2024
Microsoft Exchange Curtain Reveal Tech Bulletin Header
(Updated) Microsoft Defender for Office 365: Tenant Allow/Block List will support IPv6 allow and block entries
October 14, 2024