I'm currently trying to use Powershell to connect to a remote desktop, run a program on that desktop, and then log off. I am then checking the output of running that command across a fileshare. Basically this means that PowerShell should wait for the process to complete before continuing.
After reading up, I've been trying to use the Start-Process -Wait option to make sure that it waits for the process to run. However, this script must be run as a scheduled task, and it seems that whenever the script is run when the user is not logged in, the -wait does not work and the script continues on without the process completing. I've tried several different options for waiting, but obviously I have to run the scheduled task while the user is logged off to test it, and testing gets exhausting. Here is my current line of code executing this:
$proc = $(start-process $path -Wait)
Note that I've tried using the -NoNewWindow command, but it is not available on my verison of PowerShell.
Anyone have any other ideas for how to make it wait for the process?