ForEach-Object -Parallel Parameter set cannot be resolved

Question:

When using powershell and following this article running the following example throws an error.

Example:
1..5 | ForEach-Object -Parallel { "Hello $_"; sleep 1; } -ThrottleLimit 5

Error:
ForEach-Object : Parameter set cannot be resolved using the specified named parameters.

Removing the body of the loop does not resolve the issue. It is present whenever using the -Parallel keyword.

The article is from last year which makes me think the feature must still be present in powershell. Am I missing something obvious here?

Answer:

I ran into this issue when trying to test the script in the Windows Powershell ISE script editor, despite pwsh --version telling me that it was 7.2.0.

As Owain Esau points out in the comments, the error is telling you that the current version of ForEach-Object does not support the -Parallel parameter.

But if you open run your script in a dedicated Powershell 7 window, it should execute just fine.

Source:

ForEach-Object -Parallel Parameter set cannot be resolved by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply