Getting information about MSI files

Today I ran into an interesting continuous integration-type scenario.  One of the skunkworks projects that I’m looking at internally yields frequent builds of MSI files for the same product.  These MSI files are automatically generated (sometimes daily) by our source control system.

So I have a machine where I’ve got this MSI installed.  Let’s call it “Installer.MSI” and when I look in Add/Remove Programs it shows up as “Installer v1.9.0.”  Very nice.  Now I have a new build today.  What if I wanted to upgrade to the “today” build?

I came up with this little case statement:

Has ____ build installed DO:
no Install MSI using msiexec.exe
old Uninstall Old MSI using msiexec.exe, then Install MSI using msiexec.exe
same No installs, just watch videos online

This is the problem that I found though – although I can get version information about the MSI file…

Get-Item - with VersionInfo
Get-Item – with VersionInfo

…and I can get version information about the current installed version…

Get-WmiObject -Class Win32_Product
Get-WmiObject -Class Win32_Product

… the two don’t correlate together.  There’s no “ProductVersion” information available via the metadata on the MSI.

Turns out that’s because the good details are stored in WITHIN the MSI database – like files are in a computer.

The files are IN the computer?
The files are IN the computer?

So, I poured over the Bing and Google references and ended up on an MSDN page and on a page on Nickolaj Andersen’s (@NickolajA) website.

Now I read thought the entire script and it seemed fairly straightforward, but I wasn’t familiar with the intricacies of the ComObject.  Nickolaj set it up as a script with parameters.  I took his information and refactored it as a PowerShell function.

I’m going to place the entire script here for download and consumption.

If you find this script useful, please let me know.

If you find a problem with this script, please let me know.

Ultimately, if there’s something with this script in some way, shape, or form, feel free to let me know.

Until next time crew!

Leave a Comment