Reputation: 1804
I have 3 Powershell scripts: A.ps1
, B.ps1
, RunAB.ps1
.
A.ps1
and B.ps1
are on the same machine, RunAB.ps1
is on a different machine.
I want RunAB.ps1
to run. via remote powershell, A and B at the same time (i.e, in parallel).
Both A and B take about 2-3 days to finish run.
In order to do this, I wrote RunAB.ps1
(relevant lines only):
Invoke-Command -ComputerName $physical_server_ip -ScriptBlock {Set-Location "C:\Test"; Powershell.exe -File "A.ps1"} -Credential $physical_credential -AsJob
Invoke-Command -ComputerName $physical_server_ip -ScriptBlock {Set-Location "C:\Test"; Powershell.exe -File "B.ps1"} -Credential $physical_credential -AsJob
This runs fine at the beginning, but after about 2 hours, the powershell processes of both A and B on remote machine are terminated (they didn't finish)...
If I remove the AsJob
from second Invoke-Command
(what causes RunAB.ps1
to wait at this command) then it seems to fix the issue - A and B keep on running on remote machine, however I don't want RunAB.ps1
to wait..
What is the correct way of doing what I want?
Thanks
Upvotes: 0
Views: 177
Reputation: 10044
You'll need to extend the Idle Timeouts of the PSSession you are connecting to. The Default is 7200000
which is 2 hours
To see the current timeout values:
Get-PSSessionConfiguration | Select-Object Name, *Timeout*
To set the timeout value:
Invoke-Command -ComputerName $physical_server_ip -SessionOption {New-PSSessionOption -IdleTimeout XXXXXXX} ...
#Where XXXXXX is the value in milliseconds less than the Max timeout.
Upvotes: 2