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:
- Remove existing mail flow rules (also known as transport rules)
- 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)
- Remove all existing mail flow rules:
Get-TransportRule | foreach { Remove-TransportRule $_.Guid -Confirm:$false } - 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.