kumar
kumar

Reputation: 9417

how to run remote program on Powershell for long running program

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


}

Upvotes: 2

Views: 644

Answers (1)

Patrick
Patrick

Reputation: 2208

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

Upvotes: 1

Related Questions