2

I need to run a long running program on a remote computer. Currently the exe runs as long as the PS session exists. if the session is removed the exe stops. How can i have the exe running even if the PS session is lost

$mmoVMTemplate = "Machine"


for($i=1;$i -le 80; $i++)
{


        $mmoVM = $mmoVMTemplate + $i


        .\InstallWinRMCertAzureVM.ps1 -SubscriptionName 'my subscription' -ServiceName $mmoVM -Name $mmoVM

        $secPassword = ConvertTo-SecureString 'password' -AsPlainText -Force
        $credential = New-Object System.Management.Automation.PSCredential('username', $secPassword)
        $uri = Get-AzureWinRMUri -ServiceName $mmoVM -Name $mmoVM

        $session = New-PSSession -ConnectionUri $uri -Credential $credential

        Invoke-Command -Session $session -ScriptBlock {Set-Location "C:\MyProgram\"
        start-process -FilePath 'C:\MyProgram\TestTool.exe'}


        Disconnect-PSSession -Session $session

        Write-Host $mmoVM


}
2
  • You're not talking about the Disconnect-PSSession causing the program to exit, right? You're talking about doing a Remove-PSSession (or the session times out) causing the program to exit. Commented Aug 24, 2014 at 17:51
  • currently i am using Disconnect-PSSession as a stop gap to make it work. Remove-PSSession is causing the program to exit Commented Aug 24, 2014 at 18:11

1 Answer 1

1

Use the parameter -Wait by start-process -FilePath 'C:\MyProgram\TestTool.exe' -Wait.
So the invoke comamnd waits until the TestTool.exe is finished.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.