4

When I have a Remote PowerShell session opened and the TCP stops working (e.g. power shut/cable disconnected/...), the Invoke-Command or Remove-PSSession commands block for a few minutes trying to reconnect.

I want to reduce this timeout to 5 seconds.

At Invoke-Command, I get the warning

WARNING: The network connection to 192.168.30.106 has been interrupted. Attempting to reconnect for up to 4 minutes...
WARNING: Attempting to reconnect to 192.168.30.106 ...
WARNING: Attempting to reconnect to 192.168.30.106 ...
WARNING: Attempting to reconnect to 192.168.30.106 ...
WARNING: Attempting to reconnect to 192.168.30.106 ...
WARNING: Attempting to reconnect to 192.168.30.106 ...
WARNING: Attempting to reconnect to 192.168.30.106 ...
WARNING: Attempting to reconnect to 192.168.30.106 ...
WARNING: The reconnection attempt to 192.168.30.106 failed. Attempting to disconnect the session...
WARNING: Computer 192.168.30.106 has been successfully disconnected.
Invoke-Command : Network connectivity to 192.168.30.106 has been lost and the reconnection attempt failed. Please repair the network connection and reconnect using Connect-PSSession or 
Receive-PSSession.
At line:4 char:1
+ Invoke-Command -Session $remoteSession -ScriptBlock {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationTimeout: ([PSSession]Session7:PSSession) [Invoke-Command], RuntimeException
    + FullyQualifiedErrorId : PowerShellNetworkFailedStartDisconnect,Microsoft.PowerShell.Commands.InvokeCommandCommand

Remove-PSSession seems to use a different timeout (about 100 seconds).

Neither of OpenTimeout, OperationTimeout, IdleTimeout, and CancelTimeout does seem to affect these timeouts.

I guess I need something some lower level timeout option for that. Does that exist somewhere?

Axel Williot
  • 485
  • 6
  • 13

0 Answers0