Merge Transport Rules from One Tenant to Another

We were migrating one of our Client from one Tenant to Other. They want to move the transport rules on Exchange online in the first tenant to the second Tenant.

Issue is that second tenant also has some transport rules, so transport rules need to be merged instead of move.

Here are the Steps that needs to be followed to achieve this:

On first tenant

  1. Connect to Exchange online thru PowerShell using (Exchange Online Management Module)

    Connect-ExchangeOnline


  2. Execute below commands to export all transport rules in xml file.

    $file = Export-TransportRuleCollection

    Set-Content -Path “c:\temp\TransportRulesFirstTenant.xml” -Value $file.FileData -Encoding Byte

  3. Disconnect from Exchange online

    Disconnect-ExchangeOnline

On Second Tenant follow the Same steps

  1. Connect to Exchange online thru PowerShell using (Exchange Online Management Module)

    Connect-ExchangeOnline

  2. Execute below commands to export all transport rules in xml file.

    $file = Export-TransportRuleCollection

    Set-Content -Path “c:\temp\TransportRulesSecondTenant.xml” -Value $file.FileData -Encoding Byte

  3. Disconnect from Exchange online

    Disconnect-ExchangeOnline

Now use any popular XML editor and edit the XML file for the second tenant.

(I have used Notepad++)


Open the XML file of first Tenant as well in the Notepad++ , Use Cntrl + H and replace -Mode Enforce to -Enabled $False -Mode Enforce


Please check carefully that rule that are already disabled are not duplicated with -Enabled $False -Enabled $False -Mode Enforce, if that is the case then replace -Enabled $False -Enabled $False -Mode Enforce with -Enabled $False -Mode Enforce


This will ensure all the rules are set to Disable at first when importing to the second tenant.

Now copy all the rules from it (note open/close <rule </rule>). Paste it in the second Tenant file after the last rule and before </rules>

Ones this is completed, We need to perform the XML import operation on the second Tenant.

Note: This will cause existing rules to delete first and then all rules are imported.

I had used the third trial tenant to import these rules before importing it in prod tenant so that if any errors are there it can be fixed and there is no production impact during the import process.

Below is the import process that needs to be followed:

#############################################################

Connect-ExchangeOnline

[Byte[]]$Data = Get-Content -Path “c:\temp\TransportRulesCombinedTenant.xml” -Encoding Byte -ReadCount 0

Import-TransportRuleCollection -FileData $Data

Disconnect-ExchangeOnline

#############################################################

You can see that now all rules are merged, second tenant rules (enabled) followed by first tenant rules (disabled).


You can also refer Microsoft link if you want to know about other move settings from one tenant to another.

For merging you must use the above approach else rules will be overwritten from first tenant to second and will not be merged.

 

Thanks for reading………

Tech Wizard

https://techwizard.cloud

https://syscloudpro.com/

PowerShell Cheat Book

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s