PowerShell Script – Waiting for MSI installer to Finish

So, I recently I wrote a script that needs to uninstall and install multiple MSI files. The trick is with MSI’s, is you only want to do one install  at a time therefore, I wrote a script to loop while waiting for the MSI to complete… after a bit of fiddling, I found that the best thing to check against is just that the MSIexec process is no longer running, as that would signify that the previous install is done. Here is the code:


do {
write-host "Waiting for previous install or uninstall to complete"
Start-Sleep -Seconds 30
$msitest=get-process -processname msiexec
until ($msitest.processname -notcontains "msiexec")

I had tried also to verify against add/remove programs like so:

$test=Get-WmiObject -Class Win32_Product | Where-Object {$_.name -like '*Microsoft office professional plus 2013*'}

But, the program actually registers/unregisters itself before the install/uninstall is complete, and will allow the next MSI to kick off prematurely, which of course creates problems. I also tried based on a file check with the test-path cmdlet, but I ran into the same problem. Anyway, this is a pretty qucik and easy way to wait for your installs to complete in a powershell script.

*12/10/2014 Update* Make sure you’re on Powershell v3 or higher for this to work properly.

Leave a Reply

%d bloggers like this: