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
.
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