【问题标题】:The WS-Management service cannot process the request :PowershellWS-Management 服务无法处理请求:Powershell
【发布时间】:2018-08-08 17:54:10
【问题描述】:

我随机得到以下错误

WS-Management 服务 无法处理请求。此用户最多允许 5 个并发 shell,已超过该数量。关闭现有 壳或提高此用户的配额。有关详细信息,请参阅 about_Remote_Troubleshooting 帮助主题。

我的示例代码如下所示

try
{
    $serverlist=server1...server100
    foreach($computer in $computers)
    {
    Enter-PSSession -ComputerName $computer

    $Ostype = (Get-WmiObject  -Class Win32_OperatingSystem  -ComputerName $computer -ErrorAction SilentlyContinue ).Caption 

    Exit-PSSession
}
    }
    Catch
    {
    [System.Windows.MessageBox]::Show($_.exception.message)
    }
    finally
    {
    Exit-pssession
    }

在我执行脚本的过程中有时会发生错误,所以上面的错误让我相信,我没有正确关闭我的 PSsession。

如果我做得对,请有人告诉我

【问题讨论】:

    标签: powershell


    【解决方案1】:

    解决方案 1:我们可以使用以下命令删除现有的 PS 会话

    获取-PSSession |删除-PSSession

    解决方案 2:重新启动 IIS Exchange Server

    解决方案 3: 终止计算机上的所有 wsmprovhost.exe 进程

    解决方案 4: 更新用户的限制策略并将限制提高到更高的值,例如 30,运行

    Set-ThrottlingPolicy Default* -PowerShellMaxConcurrency 30 来设置它

    【讨论】:

    • #1 是我需要的解决方案。但是每次执行/迭代都会重做进程以关闭更多会话。
    【解决方案2】:

    请尝试以下代码。它不使用交互式会话,而是使用 Invoke-Command cmdlet。

    try
    {
        $serverlist=server1...server100
        foreach($computer in $computers)
        {
        $s = New-PSSession -ComputerName $computer 
        Invoke-Command -Session $s -ScriptBlock {$os = (Get-WmiObject  -Class Win32_OperatingSystem  -ComputerName $computer -ErrorAction SilentlyContinue ).Caption}
    
         Remove-PSSession -Session $s
        }
    }
    Catch
    {
        [System.Windows.MessageBox]::Show($_.exception.message)
    }
    

    【讨论】:

    • 澄清答案:Remove-PSSession 确实应该删除会话(Exit-PSSession 将使其处于断开状态)。
    猜你喜欢
    • 2021-04-29
    • 2022-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-03
    相关资源
    最近更新 更多