Tag Archives: wait

Fix: PowerShell does not wait before starting the next command

When creating a Powershell script and executing something in the middle of the script it does not wait until that process finishes and continues executing the script.

This can be a pain since you might have something executing after the script which depends on the executable you run.

So, when you are executing the file and you want Powershell to wait before continuing you must add the following for it to wait until it finishes.

&Myfile.exe | Out-Null

By adding the Out-Null after your script, it will wait until the MyFile.exe finishes before continuing executing.

This method can be used for the Start-Process as below

Start-Process MyFile.exe -NoNewWindow -Wait

Or you can use this to the Wait For Exit parameter

$proc = Start-Process -NoWindow
$proc.WaitForExit()

(32)