i-think Twenty-Two

Now with more coherency.

Installing multiple MSI files using msiexec.exe and Powershell

| Comments

I use Powershell scripts to update test environments and when I can I prefer to use the MSI files that we would ship to a customer rather than hacking together an xcopy deployment. Recently I worked on a script that did the following:

  1. Check if an MSI already exists in a folder I designated as holding the current installation files (I called it ‘Current’).
  2. If the MSI exists, execute the uninstall process for the MSI, and remove the MSI from the ‘Current’ folder.
  3. Copy the new installation file from the build drop folder and put it in the ‘Current’ folder.
  4. Execute the install process on the MSI in the ‘Current’ folder.

However I soon ran into a problem in that when I called msiexec.exe it would not block the script, so it would try to run multiple instances on Windows Installer and if you’ve had any experience with Windows Installer you know that just doesn’t work (and for good reason).

A quick search on the interwebs revealed that I could simply wait for the msiexec.exe process to finish. Rather than doing some sort of convoluted monitoring of the process inside Powershell I decided to use the the Start-Process commandlet (inspired by Heath Stewart’s post ‘Waiting for msiexec to Finish’).

Start-Process is a little bit different from ‘start’ especially in how it passes the parameters (through the -ArgumentList argument/parameter). But fortunately the -Wait parameter was exactly what I was looking for. Here’s the final line:

Start-Process -FilePath msiexec -ArgumentList /i, $installer, /quiet -Wait

This let everything nicely chain together and now deployments are super easy, as they should be.