New-PSSessionOption -OpenTimeout not actually working?

Hi,

I am using powershell remote session with a bunch of computers.

I don’t understand why the -OpenTimeout option is not working. No matter what value I give it, it always take the same amount of time before getting an error about the remote pc not being found.

My code is the following:

$pso = New-PSSessionOption -OpenTimeout 500

$session = New-PSSession –ComputerName my_pc -Credential my_credential -SessionOption $pso

It should timeout after 500 ms but it does not. Am I missing something?

 

 

As per the documentation, you are not necessarily using this incorrectly:

$PSSessionOption = New-PSSessionOption -OpenTimeout 120000

Description
———–
This command creates a $PSSessionOption preference Variable.

When the $PSSessionOption preference Variable exists in the session, it establishes default values for options in the PSSessions that are created by using the New-PSSession, Enter-PSSession, and Invoke-Command cmdlets.

To make the $PSSessionOption Variable available in all sessions, add it to your Windows PowerShell session and to your Windows PowerShell profile.

For more information about the $PSSessionOption Variable, see about_preference_variables. For more information about profiles, see about_profiles.

However, when you say, it’s taking the same amount of time before getting an error, are you saying, it’s still taking the default 3 minutes?

If so, that means you setting is not sticking, as you’ve discovered. SSo, if you do a standalone effort, say the below, what results do you get…

 New-PSSEssionOption


MaximumConnectionRedirectionCount : 5
NoCompression                     : False
NoMachineProfile                  : False
ProxyAccessType                   : None
ProxyAuthentication               : Negotiate
ProxyCredential                   :
SkipCACheck                       : False
SkipCNCheck                       : False
SkipRevocationCheck               : False
OperationTimeout                  : 00:03:00
NoEncryption                      : False
UseUTF16                          : False
IncludePortInSPN                  : False
OutputBufferingMode               : None
MaxConnectionRetryCount           : 0
Culture                           :
UICulture                         :
MaximumReceivedDataSizePerCommand :
MaximumReceivedObjectSize         :
ApplicationArguments              :
OpenTimeout                       : 00:03:00
CancelTimeout                     : 00:01:00
IdleTimeout                       : -00:00:00.0010000



 $Pso = New-PSSEssionOption
 $Pso


MaximumConnectionRedirectionCount : 5
NoCompression                     : False
NoMachineProfile                  : False
ProxyAccessType                   : None
ProxyAuthentication               : Negotiate
ProxyCredential                   :
SkipCACheck                       : False
SkipCNCheck                       : False
SkipRevocationCheck               : False
OperationTimeout                  : 00:03:00
NoEncryption                      : False
UseUTF16                          : False
IncludePortInSPN                  : False
OutputBufferingMode               : None
MaxConnectionRetryCount           : 0
Culture                           :
UICulture                         :
MaximumReceivedDataSizePerCommand :
MaximumReceivedObjectSize         :
ApplicationArguments              :
OpenTimeout                       : 00:03:00
CancelTimeout                     : 00:01:00
IdleTimeout                       : -00:00:00.0010000



 $Pso.OpenTimeOut = (New-TimeSpan -Minutes 1)
 $Pso


MaximumConnectionRedirectionCount : 5
NoCompression                     : False
NoMachineProfile                  : False
ProxyAccessType                   : None
ProxyAuthentication               : Negotiate
ProxyCredential                   :
SkipCACheck                       : False
SkipCNCheck                       : False
SkipRevocationCheck               : False
OperationTimeout                  : 00:03:00
NoEncryption                      : False
UseUTF16                          : False
IncludePortInSPN                  : False
OutputBufferingMode               : None
MaxConnectionRetryCount           : 0
Culture                           :
UICulture                         :
MaximumReceivedDataSizePerCommand :
MaximumReceivedObjectSize         :
ApplicationArguments              :
OpenTimeout                       : 00:01:00
CancelTimeout                     : 00:01:00
IdleTimeout                       : -00:00:00.0010000