I am using a Powershell script to launch an application, which in this case includes applying some settings before the application runs, then cleaning up once it exist. I don't want the Powershell window to be visible the whole time the app is running, so I'm launching it in a hidden window.
Inside the script, I use Start-Process to launch the application, and I use the -Wait parameter so that the script won't continue until the application exist. But the script is not waiting for the app; it just continues on. I have verified that -Wait works if the window is not hidden.
In the TechNet refernce page for the Start-Process command, it says that the -Wait parameter "suppresses the command prompt or retains the window until the process completes." Since there is no window in this case, I suspect this may be the cause.
There's a simple workaround - I use the -Passthru parameter with Start-Process, capture the process in a variable, and test the variables's .HasExited property every 12 seconds.
Thanks,
Graham