Ken Robertson
Ken Robertson

Reputation: 63

is there a wait parameter in PowerShell to allow the script to wait until a command is completed

I trying to install a software using Start-Process in PowerShell, I would like for the script to wait until a command is completed before proceeding to the next one. I'm not experienced I tired the script below but it did not work.

Start-Process -Wait -FilePath "C:\Temp\Latitude_5X10_Precision_3550_1.15.0.exe" -ArgumentList "/S" -PassThru

Upvotes: 2

Views: 174

Answers (1)

mklement0
mklement0

Reputation: 437753

Your Start-Process call is correct, but -Wait invariably only tracks the lifetime of the directly launched process (C:\Temp\Latitude_5X10_Precision_3550_1.15.0.exe in your case).

That is, you're out of luck if the target process itself spawns yet another process in order to perform its task and then returns before that child process has terminated.

Additional work is then needed, if even feasible:

  • If you know the name of the child process, you can try to find and track it via Get-Process.

  • Alternatively, if you know of an indirect sign that the task has completed, such as the existence of a directory or a registry entry, look for that.


As an aside: console(-subsystem) applications can be invoked directly for synchronous (blocking) execution (e.g., foo.exe bar baz or & $fooExePath bar baz), which is the preferred method, because it connects the application's output streams to PowerShell's streams.

Upvotes: 1

Related Questions