Windows WinRM 错误: 解决问题指南
这是一个错误. "The WS-Management service on the remote machine cannot process the shell request" typically occurs when you try to establish a remote PowerShell session (Enter-PSSession) or run a remote command (Invoke-Command) using Windows Remote Management (WinRM).
错误的描述
这个错误意味着目标 (远程) 计算机上的 WinRM 服务接收了您的连接请求,但无法为您创建命令.最常见的根源原因包括:
- MaxShellsPerUser limit reached: 远程机器对单个用户可以同时打开多少远程命令shell有严格的限制.如果以前的会话没有正确关闭,服务器会阻止新的.
- MaxMemoryPerShellMB limit exceeded: 在您的远程会话中运行的进程需要比远程机器上配置的限制更多的RAM.
- WinRM service corruption: WinRM 服务或其收听器配置错误或挂在远程机器上.
逐步修复问题
您必须将这些修复应用于 remote machine (您试图连接的计算机). 直接或通过远程桌面 (RDP) 登录.
修复1:增加每个用户的最大外
这是最常见的分辨率.它增加了单个用户可以保持的并发远程连接数量.
- 打开门 Start Menu 在远程计算机上.
- 它们的类型
powershell,右键点击 Windows PowerShell,并选择 Run as administrator. - 通过运行这个命令来检查您的当前限制:
Get-Item WSMan:\localhost\Shell\MaxShellsPerUser - 通过执行:
Set-Item WSMan:\localhost\Shell\MaxShellsPerUser 50 - 重新启动 WinRM 服务以应用更改:
Restart-Service WinRM
修复2:增加每一个 shell 分配的内存
如果您的脚本或命令消耗大量资源,Windows可能会因为内存限制而关闭shell请求.
- 打开 Windows PowerShell 作为一个 Administrator 在远程机器上.
- 检查当前内存限制 (通常为 1024MB默认):
Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB - 将内存限制增加到2048MB (2GB) 或更高,运行:
Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 2048 - 重新启动 WinRM 服务以应用配置:
Restart-Service WinRM
修复3: 关闭失败的PowerShell进程
如果您现在无法更改配置限制,则可以通过终止卡住的背景会话来释放空格.
- 打开 PowerShell 作为一个 Administrator 在远程机器上.
- 在您的用户帐户下运行后台PowerShell进程:
Get-Process wsmprovhost - 强制终止所有隐藏的远程主机进程,以清除您的外配额:
Stop-Process -Name wsmprovhost -Force
修复4:重新配置和重置WinRM
如果配置更改未解决问题,则 WinRM 收听器状态可能受损.
- 打开 Command Prompt (cmd) 或 PowerShell 作为一个 Administrator.
- 运行内置配置实用程序来修复收听器和防火墙例外:
winrm quickconfig - 如果提示进行更改或帮助启用服务,输入
y然后按下. Enter.
可能有一些错误.. Learn Microsoft