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.

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

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

1PS> Set-Item .\MaxShellsPerUser 120

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

1PS> Set-Item .\MaxConcurrentUsers 100

Check the configurations have been updated

1PS> dir

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

comments powered by Disqus