How do I get PowerShell to wait until the Invoke-Item call has finished? I'm invoking a non-executable item, so I need to use Invoke-Item to open it.
In addition, Windows PowerShell does not wait for the commands to finish when running executable programs. This article will show you ways to force the Windows PowerShell environment to wait for the commands with executable files to finish before moving to the following command.
The Wait-Job command determines whether all of the commands have completed within 30 seconds. It uses the Timeout parameter with a value of 30 to establish the maximum wait time, and then stores the results of the command in the $done variable.
iex is an alias for Invoke-Expression . Here the two backticks don't make any difference, but just obfuscates the command a little. iex executes a string as an expression, even from pipe. Here Start-Process is a cmdlet that starts processes.
Description. The Invoke-Expression cmdlet evaluates or runs a specified string as a command and returns the results of the expression or command. Without Invoke-Expression , a string submitted at the command line is returned (echoed) unchanged. Expressions are evaluated and run in the current scope.
Just use Start-Process -wait
, for example Start-Process -wait c:\image.jpg
. That should work in the same way as the one by @JaredPar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With