13

I'm using the following line to uninstall office 2007 based on its Product ID

Start-Process C:\Windows\System32\msiexec.exe -ArgumentList "/uninstall {90120000-0030-0000-0000-0000000FF1CE}"

I'd like to force a reboot after the uninstall is complete however using -Wait or piping the results to Out-Null don't wait until the uninstall is complete before processing the next line which is a restart. I've also tried using cmd to uninstall but with the same result.

cmd /c "msiexec.exe /uninstall {90120000-0030-0000-0000-0000000FF1CE}"

Is there any way to force powershell to wait until the uninstall is complete before processing the Restart-Computer command? I was thinking possibly writing something that detects when the setup.exe process stops before proceeding to the restart?

3
  • 2
    Have you tried Start-Process -Wait? Commented Oct 21, 2014 at 17:11
  • 2
    Could you use msiexec's /forcerestart option in this case? Commented Oct 21, 2014 at 17:41
  • Matt - That did the trick, using cmd /c "msiexec.exe /uninstall {{90120000-0030-0000-0000-0000000FF1CE} /forcerestart" Commented Oct 21, 2014 at 18:28

3 Answers 3

34

Start-Process has a wait parameter:

Start-Process C:\Windows\System32\msiexec.exe -ArgumentList "/uninstall {90120000-0030-0000-0000-0000000FF1CE}" -wait

The solution to restart after an misexec.exe uninstallation is to add the /forcerestart parameter to the msiexec call instead of trying to restart in powershell (Credits to Matt):

Start-Process C:\Windows\System32\msiexec.exe -ArgumentList @("/uninstall {90120000-0030-0000-0000-0000000FF1CE}", "/forcerestart")
Sign up to request clarification or add additional context in comments.

2 Comments

In case you need to use a filename instead of a GUID and that filename has spaces in it: Start-Process -FilePath "C:\Windows\System32\msiexec.exe" -ArgumentList '/i "C:\Temp\SQLSysClrTypes 15.0.2000.5.msi" /qr' -NoNewWindow -Wait
The "-wait" is not always functional; Sometime sthe job ignore the wait, like in invoke-command -scriptblock. - NoT sure why, yet...
15

The simplest workaround: pipe the result. This will force a wait until the process is finished.

No need for start-process or cmd.

You could pipe to out-default, out-file, out-null or out-host, depending on how you want to handle the output. (If you don't care about the output, simply use out-null.)

& msiexec.exe /uninstall "{90120000-0030-0000-0000-0000000FF1CE}" | Out-Null    

2 Comments

This should be the answer. However. I would pipe to Write-Verbose so that you can inspect the output if so required.
+1 for this answer althought the current accepted answer (Start-Process) is more explicit in intention. I like this solution though so I still used it.
0

My suggestion for this is to actually get the Office Removal Tool from Microsoft and extract the VBS script from it. Run that in a Start-Process with the -wait argument, and reboot afterwards. It will not only attempt to gracefully remove Office with msiexec as you are doing, it will also go back and clean up any straggling files or registry entries in case the application is corrupt and will not uninstall nicely.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.