修复 WinRM 错误: 无效流 ID 索引
错误的描述
这个错误发生在 Windows Remote Management (WinRM) 这种情况通常发生在使用 PowerShell Remoting 或像Ansible和Jenkins这样的工具.
The error triggers because the WinRM client and server get out of sync during data transmission. Specifically, the client sends a data packet with a stream ID index 服务器无法识别或支持.这种不匹配通常是由:
- Corrupted WinRM sessions 在后台挂着.
- Outdated PowerShell versions 在本地机器和远程机器之间.
- Size limits 在WinRM请求包被超过时.
- Corrupted WinRM configurations 在主机上.
逐步修复问题
按照以下步骤来解决问题.
步骤1:重新启动WinRM服务
最快的解决方案是通过重新启动管理服务来清除悬挂的远程会话.
- 打开门 Start Menu.
- 它们的类型
cmd,右键按下 Command Prompt,并选择 Run as administrator. - 输入下面的命令并按下 Enter:
net stop winrm - 输入下面的命令并按下 Enter 让我们重新开始:
net start winrm
步骤2:增加WinRM最大封面大小
如果您的脚本发送大块数据,包可能会被截断并破坏流ID. 增加允许的信封大小可以解决这个问题.
- 保持你的管理员. Command Prompt 打开吧.
- 运行此命令来检查您的当前配置:
winrm get winrm/config - 运行这个命令将最大封面大小增加到 8192 KB:
winrm set winrm/config @{MaxEnvelopeSizekb="8192"}
步骤3:增加每个Shell的最大内存
远程的低内存配置可能会导致数据流突然失败.
- 在管理员中. Command Prompt 运行下一个命令:
winrm set winrm/config/winrs @{MaxMemoryPerShellMB="2048"} - 重新启动 WinRM 服务,以应用更改:
net stop winrm && net start winrm
步骤4:重新注册并重置 WinRM 配置
如果配置参数受损,您可以将整个WinRM设置重置到默认设置.
- 打开 PowerShell 作为一个 Administrator.
- 运行此命令完全重置WinRM服务配置:
winrm quickconfig -q - 如果您正在配置安全环境,请确保您的设置允许远程连接,运行:
Enable-PSRemoting -Force
步骤5:更新Windows管理框架 (WMF)
Ensure both the source machine and the target machine are running compatible versions of PowerShell.
- 通过在PowerShell中运行此操作来检查您的当前版本:
$PSVersionTable.PSVersion - If either machine is running an older version (like PowerShell 4.0 or lower), download and install the latest Windows Management Framework 或是 PowerShell 7+ 从微软的官方网站.
可能有一些错误.. Learn Microsoft