Windows 错误: WinRM Shell 客户端无法处理请求
错误的描述
This error occurs when a Windows Remote Management (WinRM) session fails to receive output data from a remote machine. The specific function WSMansReceiveShellOutput 如果网络中断,缓冲区溢出,数据大小不匹配或腐败发生在传输过程中,所需参数将变为零或零,导致WinRM客户端失败并中止操作.通常在长时间运行的脚本,大量数据传输或当局部和远程机器之间PowerShell/WinRM包尺寸配置不兼容时触发.
逐步修复问题
Follow these solutions step-by-step to resolve the issue. You must run these commands on both the client (your machine) and the server (remote machine) 除非另有规定.
解决方案1:增加 WinRM MaxEnvelopeSizeKB
最常见的原因是返回的数据超过了WinRM允许的默认最大数据包大小.
- 按下 Start menu, 类型
cmd,右键点击 Command Prompt,并选择 Run as administrator. - 通过执行下一个命令检查当前的最大信封大小:
winrm get winrm/config - 在客户端和远程机器上增加封装大小,以允许更大的数据包 (例如,将其更改为8192 KB):
winrm set winrm/config @{MaxEnvelopeSizeKB="8192"} - 重新启动 WinRM 服务以应用更改:
net stop winrm net start winrm
解决方案2:增加WSMan提供者 MaxMemoryPerShellMB
如果远程 shell 在处理输出时耗尽分配的内存,则函数参数会失败.
- 打开 PowerShell as an Administrator.
- 通过运行检查每 shell 的当前内存限制:
Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB - 增加内存限制到 2048 MB (或更高,取决于您的系统资源) 以防止内存状态:
Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 2048 - 重新启动 WinRM 服务以提交配置:
Restart-Service winrm
解决方案3:修改PowerShell脚本中的输出缓冲区
如果在特定命令或脚本中发生错误,输出流可能会压倒管道.您可以强迫命令以较小的批量处理输出或清除缓冲区.
- 打开脚本,找到导致错误的命令.
- 附加文
| Out-Buffer -Count 1命令强制立即处理每个数据行,而不是缓存一个大批量.Get-WinEvent -LogName Application | Out-Buffer -Count 1 - 另外,如果您不需要详细的输出流,则将错误和语输出重定向到null:
Your-Command-Here 2>$null 3>null 4>null
解决方案4:重置和重新配置WinRM设置
如果配置参数受损,将 WinRM 架构重置到默认状态可以解决隐藏的问题.
- 打开 Command Prompt as an administrator.
- 完全禁用 WinRM 收听器配置:
winrm invoke ResetListener winrm/config/listener?Address=*+Transport=HTTP - 重新启动快速配置向导修复端点和防火墙规则:
winrm quickconfig -q
可能有一些错误.. Learn Microsoft