Duplicate Rule Detection Export and publish in CRM Dynamics 2015

I have set up custom duplicate rule detection on some entities’ fields on a DEV CRM 2015 instance. I needed to export the settings to be able to import into other environments.

I used the link Export Duplicate Detection Rules from one organization and import to another organization in CRM 2013 to export the rules. However the CRMDataMigrationUtility.exe SDK tool exports only unpublished duplicate detection rules which I had to do to be able to export the settings.

This means the detection rule has to be published afterwards. Instead of doing it manually, I have written a PowerShell script which can publish a specific rule or all rules for an entity.
The code is below.

After running the script the following message is displayed.