Increase WinRM / PowerShell Limits

For many organisations, PowerShell remoting is done through a scripthost server where maximum concurrent session limits and maximum connected user limits can be reached.

As explained in this Microsoft blog, the following error might be encountered.

PS> New-PSSession
[localhost] Connecting to remote server failed with the following error message : 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.
+ CategoryInfo          : OpenError: (System.Manageme….RemoteRunspa
ce:RemoteRunspace) [], PSRemotingTransportException
+ FullyQualifiedErrorId : PSSessionOpenFailed

Open a PowerShell session and run the following commands to get the current config.

PS> cd WSMan:\localhost\Shell
PS> dir

Run the command below to increase the number of maximum shells per user

PS> Set-Item .\MaxShellsPerUser 120

Run the command below to set the maximum number of concurrent users

PS> Set-Item .\MaxConcurrentUsers 100

Check the configurations have been updated

PS> dir

For the configurations changed above, I would recommend a minimum of 2 vCPU and 4 GB Memory.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.