#PSTip Wait for executable to finish

Sometimes you need to wait for an executable to finish its job. The typical case is a Setup.exe, but this behavior is also ideal candidate for cleaning up temporary files after an application has been closed. Powershell makes this easy; just redirect the output to a (valid) pipe.

& 'C:\Program Files\Internet Explorer\iexplore.exe' | echo "Waiting."
"Internet Explorer has been closed."
Please notice that the invoke operator ‘&’ is used, and that the “Waiting.” message is not shown in the Powershell output.
The typical case is waiting for setup.exe or msiexec.exe to finish, but the behavior is also useful for tasks like cleaning up temporary files or starting external applications one after another.

About the author: Jakub Jareš

Jakub Jareš is an IT professional with strong background in Windows desktop systems. He started with Powershell a few months ago, and couldn't let go ever since. Showing that with the right attitude, a bit of effort and lot of practice you can become advanced in Powershell in no time.

Related Posts

%d bloggers like this: