解决Windows错误:WinRM Shell客户端参数零或零
错误的描述
这个错误发生在使用 Windows 远程管理 (WinRM) 工具通过 Windows 远程来执行远程系统上的命令时 ( winrs 具体的信息 The WinRM Shell client cannot process the request. One of the parameters required for the WinrsCloseShell function is null or zero indicates a protocol mismatch, unexpected connection termination, or session corruption.
它通常发生在远程主机意外终止命令执行语境时,或者当网络设备,防火墙或安全软件在会话中期阻止通信时.它也可能是由过时的WinRM配置,目标服务器上的受损的shell会话或强制执行攻击性的连接时间过期的严格组策引起的.
逐步修复问题
您可能需要在本地机器和远程目标机器上的管理权限.
步骤1:在两个机器上重新启动 WinRM 服务
损坏的内存状态或暂停会话可能导致此错误.重启 Windows 远程管理服务将清除现有会话.
- 按下 Windows Key + X 并且选择 Terminal (Admin) 或是 Command Prompt (Admin).
- 输入下面的命令来停止服务:
net stop winrm - 输入下面的命令重新启动服务:
net start winrm - 在您的本地计算机和您试图连接的远程服务器上执行这些步骤.
步骤2:增加每个Shell的WinRM最大 Shell和最大内存
如果您的会话达到远程服务器上分配的最大资源限制,迫使服务器意外关闭外,则会出现错误.
- 打开 PowerShell 或命令提示符 Administrator 在 remote machine.
- 运行下列命令来检查当前配置限制:
winrm get winrm/config/winrs - 通过执行:
winrm set winrm/config/winrs @{MaxMemoryPerShellMB="2048"} - 通过执行:
winrm set winrm/config/winrs @{MaxShellsPerUser="30"} - 在远程机器上重新启动 WinRM 服务,使用步骤 1 中的指令来应用更改.
步骤3:验证和重新注册 WinRM 服务组件
缺失的基础设施配置或听器损坏可能会在会话中期丢失参数.重新应用快速配置命令可以解决结构问题.
- 打开PowerShell作为一个 Administrator 在 remote server.
- 执行自修设置命令:
winrm quickconfig - If the service is already configured, it will analyze your environment. If it asks you to make changes or open firewall exceptions, type
y然后按下. Enter.
步骤4:调整网络时间止息和保持活跃的设置
如果防火墙或物理负载平衡器丢弃置连接,WinRM客户端将试图关闭服务器上不再存在的 shell,导致零参数错误.
- 打开PowerShell作为一个 Administrator 在你的 local machine.
- 运行下一个命令来检查客户端的时限值:
winrm get winrm/config/client - 为了防止过早的断线下降,将运行时间限制提高到5分钟 (300,000毫秒):
winrm set winrm/config/client @{Timeout="300000"}
步骤5:检查Windows更新和PowerShell版本的兼容性
A known protocol bug in older versions of the Windows Management Framework (WMF) can trigger this specific WinrsCloseShell 在不同Windows服务器版本之间通信时出现错误.
- 在两个机器上检查您的PowerShell版本:
$PSVersionTable.PSVersion - 如果您的远程机器正在运行 Windows Server 2012 或 Windows Server 2016 已过时的 WMF 5.1 版本,请导航到 Windows 更新.
- 在两个机器上安装所有等待的累积质量更新,
可能有一些错误.. Learn Microsoft