I am working on a piece where I have to start an application and this application should be keep running in background. I tried Start-Process cmdlet as below:
try {
Invoke-Command -Session $newsession -Scriptblock {
Write-Host "Cd'ing and starting Vesper on" $loadvm
Start-Process cmd -ArgumentList "/c C:\vesper_cpt\Vesper.exe -auto" -verb runas
} -ErrorAction Stop
} catch [Exception] {
echo "Error while running the remote command", $_.Exception.GetType().FullName, $_.Exception.Message
Remove-PSSession $newsession
exit 1
}
Remove-PSSession $newsession
What is happening is that I can see that it starts a cmd process on the target machine but then it immediately goes away. I am not sure what should I do here to have that process up and running always. On the other hand, I also tried Invoke-Expression cmdlet and with this I can see the process has started fine on the remote machine but the powershell script never returns and that is why thought of using Start-Process. Any suggestions?