5

In powershell I am trying to create a remote session. It fails (and that's ok, I know why it fails) but the issue is that I am trying to set a failure timeout.

I create a New-PSSessionOption and set the OpenTimeout in milliseconds, but it seems that no matter what it always takes the same amount of time: 15 seconds.*

$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
$pso = New-PSSessionOption -OpenTimeout 10000
$server = "hostname"
$session = New-PSSession -ComputerName $server -Credential $cred -SessionOption $pso
...
Remove-PSSession $session

The error message which happens at the New-PSSession line, in case it is relevant to why the timeout isn't being applied, is this:

Connecting to remote server "hostname" failed with the following error message : WinRM cannot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over the network, and that a firewall exception for the WinRM service is enabled and allows access from this computer. By default, the WinRM firewall exception for public profiles limits access to remote computers within the same local subnet. For more information, see the about_Remote_Troubleshooting Help topic.

Edit: * When changing the OpenTimeout value it seems that it changes but stays within a certain range, 5-20 seconds. Perhaps there is an undocumented minimum and maximum for this parameter?

user9057586
  • 133
  • 7

0 Answers0