How do I make PowerShell wait for the command to complete before continuing?

I am using the following line to uninstall Office 2007 based on Product ID

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

      

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

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

      

Is there a way to force powershell to wait for the uninstall to complete before processing the Restart-Computer command? I was thinking maybe something that detects when the setup.exe process stops before proceeding to restart?

+3


source to share


2 answers


There is a wait parameter during the startup process:

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

      



The solution to restart after uninstall is misexec.exe

to add a parameter /forcerestart

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")

      

+14


source


My suggestion is to actually uninstall the Office uninstall tool from Microsoft and extract the VBS script from it. Run this in Start-Process with the -wait argument and restart later. Not only will it try to gracefully uninstall Office with msiexec as you do so, it will also come back and clean up any debugging files or registry entries if the application is corrupted and not removed nicely.



0


source







All Articles