I am working on a script to remotely kill two processes, delete some folders, and launch a service as an application. Eventually this will be deployed to run against multiple servers, but I'm currently testing it against a single server. Everything works great except for the final step which is to launch the remote service (which is being run as an application using the -cl argument due to some compatibility issues with it running as a service). The application launches via the script but immediately shuts back down as the script moves on to the next step. I'm a total noob so I've been digging quite a bit but have had no luck finding a solution. It seems like I may end up having to launch the process in a new runspace, but I'm not having any luck finding a good noob guide for doing that either.
Also the script performs just as it should when localized and run on the machine.
Here's what I've got
$a = Get-ChildItem "\\TestMachine\c$\DataFiles"
$pass = cat "C:\cred.txt" | convertto-securestring
$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist "username",$pass
if ($a.Count -gt 10)
{
Invoke-Command -ComputerName TestMachine -cred $mycred -scriptBlock {stop-process -name TestProcess -force -EA SilentlyContinue}
Invoke-Command -ComputerName TestMachine -cred $mycred -scriptBlock {stop-process -name Winword -force -EA SilentlyContinue}
Get-ChildItem -Path \\TestMachine\c$\WordDocs -Recurse -EA SilentlyContinue | Where-Object {$_.PsIsContainer} | Remove-Item -Recurse -Force -EA SilentlyContinue
Invoke-Command -ComputerName TestMachine -cred $mycred -scriptBlock {Start-Process "C:\Program Files (x86)\Test\TestUploadManager\TestUploadManager.exe" -Verb Runas -ArgumentList -cl}
echo "Success: TestMachine Was successfully reset"
}
else
{
echo "Failed: Reset was not necessary"
}
exit