Does PowerShell have a limit that causes the error

2019-08-06 11:02发布

问题:

We have a deployment script that is failing with the error message: Not enough quota is available to process this command.

At the point where it fails it is attempting to start an executable asynchronously after having already started the same executable 10 times. So number 11 fails. A total of 17 need to be started. This script is not written in PowerShell but we use a remote PowerShell session to launch it and this error only happens when we run the script via PowerShell remoting.

If we run the same script directly on the server without using PowerShell remoting we don't get this error and the script has no problem launching all instances of the exe (17 in total) and finishing without error.

I have checked on the typical WSMAN limits that I suspected might be the cause of the error and they are set to unlimited as far as I can tell. At first I thought maybe MaxProcessesPerShell was set too low. Here are the results from the WSMAN drive on the server where this is running:

We have these WSMAN settings currently:

> WSMan:\localhost\Shell> dir

   WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Shell

Type            Name                           SourceOfValue   Value
----            ----                           -------------   -----
System.String   AllowRemoteShellAccess                         true
System.String   IdleTimeout                                    7200000
System.String   MaxConcurrentUsers                             2147483647
System.String   MaxShellRunTime                                2147483647
System.String   MaxProcessesPerShell                           2147483647
System.String   MaxMemoryPerShellMB                            2147483647
System.String   MaxShellsPerUser                               2147483647

Is there any other PowerShell or WSMAN setting that might be the cause of this error?

The typical solution that is recommended for the Not enough quota... error involves making the Page file bigger. I have not tried that yet because the script runs error free outside of a PowerShell session.

I can provide more specifics about what our script is doing if that is needed to help answer this question.

回答1:

The quota limit that was causing my error was the MaxProcessesPerShell setting on the PowerShell 32 bit plugin. This setting is independent of the Shell setting. To fix the issue I ran the follow commands in the remote PowerShell session...

 dir WSMan:\localhost\Plugin\microsoft.powershell32\Quotas\MaxProcessesPerShell

Results...

Type            Name                           SourceOfValue   Value
----            ----                           -------------   -----
System.String   MaxProcessesPerShell                           15

Change the setting to 25 with...

Set-Item WSMan:\localhost\Plugin\microsoft.powershell32\Quotas\MaxProcessesPerShell 25

Restart the WinRM service with...

Restart-Service WinRM

Tried running the problem script again with this new quota in effect and it now launches all 17 instances of the exe without any error. There is also a 64 bit PowerShell plugin which has it's own setting for this too.

This solution was found here Not enough quota is available to process this command