How To: Run Several Programs Sequentially in PowerShell [Field Notes]

less than 1 minute read | Suggest an edit | Issue? Question?

Problem:

I want to run several installation programs in order, and don’t want them to step on each other.

I want to avoid errors such as “another setup program is already running” which result in the second install not completing.

Solution

For files without arguments, run:

$var1 = Start-Process -FilePath "[path]" -passthru
$var1.WaitForExit()

For files with arguments, run:

$var1 = Start-Process -FilePath "[path]" -ArgumentList "[Args]" -passthru
$var1.WaitForExit()

In these examples, [path] is the full path to the file (e.g. C:\SomeFolder\MyProgram.exe) you want to run. [Args] is whatever you’d normally put after the path to the exe in the command line.

NOTE: Single quotes around the file path will ensure the command will not break if it includes a space in the path.

Updated:

Leave a comment