Is there a way to make powershell wait for an install to finish? Is there a way to make powershell wait for an install to finish? powershell powershell

Is there a way to make powershell wait for an install to finish?


Start-Process <path to exe> -Wait 


JesnG is correct in using start-process,however as the question showed passing arguments, the line should be:

Start-Process "mypatch.exe" -argumentlist "/passive /norestart" -wait

The OP also mentioned determining if the install succeeded or failed. I find that using a "try, catch throw" to pick up on error states works well in this scenario

try {    Start-Process "mypatch.exe" -argumentlist "/passive /norestart" -wait} catch {    # Catch will pick up any non zero error code returned    # You can do anything you like in this block to deal with the error, examples below:    # $_ returns the error details    # This will just write the error    Write-Host "mypatch.exe returned the following error $_"    # If you want to pass the error upwards as a system error and abort your powershell script or function    Throw "Aborted mypatch.exe returned $_"}


Sure, write a one line batch script that runs the installer. The batch script will wait for the installer to finish before returning. Call the script from PowerShell which will in turn wait for the batch script to finish.

If you have access to how mypatch is written, you could have that create some random file when it completes that PowerShell can check for its existence in a while loop and just sleeps while the file doesn't exist.

If you don't, you could also have that batch script create a dummy file when the installer completes.

Yet another way, though probably the worst of all of these is to just hard-code a sleep timer (start-sleep) once you call the installer.

EDIT just saw JensG's answer. Didn't know about that one. Nice