So I came across quite a problem when I lost one of the MP files for one of my custom management packs. I had a new, updated version, but how do I verify upgrade compatibility without the file?
In a normal situation when you have both of the files, you can use the mpverify.exe utility to do so. That would look something like this:
mpverify managementpack.xml /I C:\MyManagementPackDir /CheckUpgrade C:\OldMPs\OlderVersionOfMP.xml
I was in quite a quandry because I lost the older version. However, there is an option!
Using the Microsoft.EnterpriseManagement.Configuration namespace, there is a handy class called ManagementPack, which in turn has a member called CheckVersionCompatibility()
At first, I was a little puzzled, as this method can only check the instance of ManagementPack against an OLDER version of itself.
Soon after I realized the constructor for ManagementPack can take a file path. Looks something like this:
$newmp = [Microsoft.EnterpriseManagement.Configuration.ManagementPack](“C:\InsertMPNameHere.xml”)
So now I have my updated version in an Object, from which I can call the CheckVersionCompatibility() method, which will verify the managementpack for me, which looks like:
$currentmp = get-managementpack –name “InsertMPNameHere”
$newmp.CheckVersionCompatibility($currentmp)
Sweet! It works! But wait. It tell me it worked, how can I be sure? It returns System.Void?
After consulting with the infamous Jakub@Work, he ensured me that the only time it fails is when it throws a ManagementPackException.
They could have at least told it to return 0 if it worked correctly. Instead the only option is to hope it throws an exception to tell you something is wrong.
So, if you’re going to use ManagementPack.CheckVersionCompatibility(), put it in a trusty try-catch statement so you can handle the exceptions in the way of your choice.