1

Please help, this feels so trivial yet I have been trying innumerous variations - to no avail.

I have been trying to get the OperationTimeout parameter to work when opening a powershell remote session using New-PsSession.

Forget all the samples I created on my own that do not work. Let's stick with the following one, taken from here, where the poster shares the supposed output showing that the OperationTimeout setting does close the session, if the defined time limit is exceeded.

Am pasting the referred post snippet as an image since there is no direct link to the code below, you would rather have to navigate CTRL + F after OperationTimeout.

enter image description here

The code snippet I am using to test the post's example is the following:

$password = "myPass"
$domainAndUser = "myDomain&User"
$computerName = "myRemoteComputerIp"
$pwSession = convertto-securestring -AsPlainText -Force $password
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $domainAndUser,$pwSession
$pso = New-PSSessionOption -OperationTimeout (5*1000)
$session = new-pssession -computername $computerName -credential $cred -SessionOption $pso
Invoke-Command $session { 1..10 | foreach {"$_" + ('*' * $_) ; Start-Sleep 1} }

What the heck is wrong/missing with the code above ? Why I do not see the timeout error message as expected ? My remote connection is successfully opened (Get-PsSession shows a new connection with state Opened).

My powershell version (Obtained via Get-Host | Select-Object Version) is 5.1.19041.1023

Veverke
  • 9,208
  • 4
  • 51
  • 95
  • I am confused. What is it you think `-OperationTimeout` does? – Abraham Zinala Jun 29 '21 at 11:00
  • @AbrahamZinala: I will be happy to learn I am the one to be declared confused :-) My understanding is that `OperationTimeout` should abort the command invocation if the number of milliseconds passed as `-OperationTimeout` is exceeded. – Veverke Jun 29 '21 at 11:30
  • @AbrahamZinala: are you able to reproduce the timeout error running my snippet ? – Veverke Jun 29 '21 at 11:34
  • @AbrahamZinala: I mean, my understanding on `OperationTimeout` seems to be backed by the output of the code snippet originally referred to in my question. Am I wrong ? – Veverke Jun 29 '21 at 11:50
  • 1
    I see the symptom also when targeting PowerShell Core 7.2.0-preview.7. If you don't get an answer here, I suggest opening an [issue in the PowerShell GitHub repo](https://github.com/PowerShell/PowerShell/issues/new/choose). – mklement0 Jun 29 '21 at 17:35
  • 1
    @mklement0: [opened](https://github.com/PowerShell/PowerShell/issues/15696) – Veverke Jun 29 '21 at 21:29
  • @mklement0: they pointed me to [this](https://github.com/PowerShell/PowerShell/issues/5434), which you opened in 2017 :) So this is not actually new to you – Veverke Jul 01 '21 at 07:02
  • :) Yes, `Invoke-Command -Timeout` would be handy, potentially even for local operations. Re `OperationTimeout`: The official response is unsatisfying, and certainly at odds with the documented behavior. And there's still a mystery that the book you cite, authored by one of the original creators of PowerShell, shows a seemingly working example. – mklement0 Jul 01 '21 at 12:38
  • Perhaps I can now inspire you to create an issue in the _docs_ repo, which you can do directly from [help topic](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/new-pssessionoption), at the bottom ("Feedback" section, button "This page". Apart from saying that `OperationTimeout` doesn't control actual command timeouts, it should also clarify whether setting this value _ever_ makes sense or has any effect. It's a bit disheartening that the need to fix the docs doesn't occur to the maintainers themselves. – mklement0 Jul 01 '21 at 12:42
  • 1
    @mklement0: I share the disheartenment. But one can only imagine that a) would I do better was I in their place ? I mean there are certainly hundreds of things around happening. In the end once you stumble across a rock in the road the best one can do is to remove it to help others avoid it. Delving in "why and how on earth can this happen" - although something I often find myself asking, ultimately lacks purpose. (so this is a self-critic, yes :) and off-the-record remark :). Back to the topic - will try to raise my hand in the *docs* section as well. – Veverke Jul 01 '21 at 13:08

0 Answers0