如何关闭孤立的 PowerShell 会话?

SuH*_*wak 5 powershell

我正在创建一个在远程服务器上使用多个“Invoke-Command -asjob”的脚本,但在测试 While-Loop 时我不得不停止它。但是,当我现在在目标服务器上尝试 Invoke-Command -asjob 时,它返回状态为 failed 的作业。当我收到作业时,它返回此错误:

The WS-Management service cannot process the request. This user has exceeded the maximum number of concurrent shells allowed for this plugin. Close at least one open shell or raise the plugin quota for this user.
+ FullyQualifiedErrorId : -2144108060,PSSessionStateBroken
Run Code Online (Sandbox Code Playgroud)

当我执行 Get-PSSession 时,没有列出,所以我不能使用 Remove-PSSession(这是 Google 迄今为止唯一的建议)。

这是它基本上执行的内容:

While ($True)
    { 
    Invoke-Command -Computername $RemoteServer -AsJob {Get-ChildItem}
    }
Run Code Online (Sandbox Code Playgroud)

我打破了它并做了Get-Job | Remove-Job 删除了所有作业,但我仍然无法在远程服务器上启动 Invoke-Command -AsJob。

我还在远程服务器上重新启动了 WSMAN 服务(通过使用 RDP 登录),但它不起作用。

Mat*_*ore 4

远程作业将在每个作业的wsmprovhost.exe进程下运行。您应该能够使用 WMI 强力终止这些进程,甚至远程重新启动计算机。当然,您面临着终止其他用户/活动的托管作业的风险。

这将终止指定计算机(或计算机名称数组)上的 所有wsmprovhost.exe进程:

(gwmi win32_process -ComputerName $RemoteServer) |? 
    { $_.Name -imatch "wsmprovhost.exe" } |% 
    { $_.Name; $_.Terminate() }
Run Code Online (Sandbox Code Playgroud)