无法让 OperationTimeout 与 New-PsSession

问题描述

请帮忙,这感觉很琐碎,但我一直在尝试无数变体 - 无济于事。

在使用 OperationTimeout 打开 powershell 远程会话时,我一直试图让 New-PsSession 参数起作用。

忘记我自己创建的所有不起作用的样本。让我们继续使用以下取自 here内容,其中发布者分享了假定的输出,表明 OperationTimeout 设置确实会关闭会话,如果超过了定义的时间限制。

我将引用的帖子片段粘贴为图片,因为没有指向下面代码的直接链接,您宁愿在 CTRL + F 之后导航 OperationTimeout

enter image description here

我用来测试帖子示例的代码片段如下:

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

上面的代码到底有什么问题/缺失?为什么我没有看到预期的超时错误消息?我的远程连接已成功打开(Get-PsSession 显示状态为 Opened 的新连接)。

我的 powershell 版本(通过 Get-Host | Select-Object Version 获得)是 5.1.19041.1023

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)