我正在创build一个在远程服务器上使用几个“Invoke-Command -asjob”的脚本,虽然在testingWhile-Loop时狂奔,我不得不阻止它。 但是,当我现在在目标服务器上尝试一个Invoke-Command -asjob时,它会返回状态为失败的作业。 当我收到作业时,返回这个错误:
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
当我做Get-PSSession时,没有列出,所以我不能使用Remove-PSSession(这是迄今为止Google的唯一build议)。
这是它基本上执行的:
While ($True) { Invoke-Command -Computername $RemoteServer -AsJob {Get-ChildItem} }
我打破了它,做了Get-Job | Remove-Job删除了所有的工作,但是我仍然无法在远程服务器上启动Invoke-Command-AsJob。
我也重新启动了远程服务器上的WSMAN服务(通过login到RDP),这不起作用。
远程作业将在每个作业的wsmprovhost.exe进程下运行。 你应该可以用WMI强行终止这些进程 – 甚至可以远程重启机器。 当然,你冒着为其他用户/活动杀掉托pipe作业的风险。
这将终止命名计算机(或计算机名称数组)上的所有wsmprovhost.exe进程:
(gwmi win32_process -ComputerName $RemoteServer) |? { $_.Name -imatch "wsmprovhost.exe" } |% { $_.Name; $_.Terminate() }