I have 1 Million Items to check with Powershell. To improve the performance, I want to use ForEach-Object -Parallel
. For this reason, I have deployed a very powerful VM.
The runspace pool size is specified by the ThrottleLimit parameter. The default runspace pool size is 5. You can still create a new runspace for each iteration using the UseNewRunspace switch.
I notice that no matter how high I set the limit, the CPU usage does not increase. Is there a technical maximum limit for this parameter? I have the impression that above a certain value the limit is simply capped.
$oneMillionItems | ForEach-Object -Parallel {
Do something ...
} -Throttlelimit 300
PS > $PSVersionTable
Name Value
---- -----
PSVersion 7.2.1
PSEdition Core
GitCommitId 7.2.1
OS Microsoft Windows 10.0.20348
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0