Reputation: 9417
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
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