How To Export/Import Exchange Online Transport Rules via PowerShell

  • Post author:
  • Post category:Microsoft

Use this PowerShell to export Exchange Online transport rules via PowerShell.

Connect to Exchange Online via PowerShell like normal.

The import will prompt you, letting you know it’ll overwrite all existing rules.

EXPORT:

Change the path to an existing path.

$file = Export-TransportRuleCollection;
Set-Content -Path "C:\Test\Rules.xml" -Value $file.FileData -Encoding Byte;

IMPORT:

Change the path to the same path you used above.

[Byte[]]$Data = Get-Content -Path "C:\Test\Rules.xml" -Encoding Byte -ReadCount 0;
Import-TransportRuleCollection -FileData $Data;

ADDITIONAL INFORMATION:

IMPORT: https://docs.microsoft.com/en-us/powershell/module/exchange/import-transportrulecollection?view=exchange-ps

EXPORT: https://docs.microsoft.com/en-us/powershell/module/exchange/export-transportrulecollection?view=exchange-ps

Jason

Jason works as a project specialist at an IT MSP in Pennsylvania, USA. He's an IT/security professional with 20 years experience.