Skip to content

Can't get OperationTimeout to work with New-PsSession #15696

@Veverke

Description

@Veverke

Prerequisites

Steps to reproduce

I can't get OperationTimeout setting to work with New-PsSession. Please refer to this post I posted earlier today in StackOverflow.

In a short, I found a supposedly working snippet at Windows Powershell In Action 2nd Edition, by Bruce Payette, at Chapter 13 - Remoting.

I slightly adapted the script to look as follows:

$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} }

I expected to see the same The WinRM client cannot complete the operation within the time specified error as described in the snippet from the book. But I am not able to achieve such result. Tried several variations.

Reproduces in both Powershell 5.1 and 7.1.3, on Windows.

Expected behavior

Error `The WinRM client cannot complete
the operation within the time specified` should be displayed.

Actual behavior

Invoke-Command script block proceeds till completion, without being aborted due timeout.

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions