TheGameiswar
TheGameiswar

Reputation: 28920

The WS-Management service cannot process the request :Powershell

I randomly get below error

The WS-Management service cannot process the request. This user is allowed a maximum number of 5 concurrent shells, which has been exceeded. Close existing shells or raise the quota for this user. For more information, see the about_Remote_Troubleshooting Help topic.

my sample code does below

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
    }

Some times errors occur during my execution of script,so the above error is leading me to believe,i am not closing my PSsession properly.

Can some one please let me know if i am doing right

Upvotes: 1

Views: 11833

Answers (2)

narendra bondukuri
narendra bondukuri

Reputation: 21

Solution 1: We can use below command to remove the existing PS Sessions

Get-PSSession | Remove-PSSession

Solution 2: Restart the IIS Exchange Server

Solution 3: Terminate the all wsmprovhost.exe process on comuputer

Solution 4: Update the throttling policy for the user and rise the limit to higher value, Ex say 30, Run

Set-ThrottlingPolicy Default* -PowerShellMaxConcurrency 30 to set it

Upvotes: 2

GNUzilla
GNUzilla

Reputation: 116

Try the following code instead. It doesn't use an interactive session but rather uses the 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)
}

Upvotes: 3

Related Questions