Joh1998
Joh1998

Reputation: 125

ForEach-Object -Parallel Parameter set cannot be resolved

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?

Upvotes: 9

Views: 11555

Answers (2)

Timothy C. Quinn
Timothy C. Quinn

Reputation: 4485

As @Kylaaa mentioned, this is a powershell version issue. Be sure you are running pwsh instead of powershell. I just learned of this distinction and although I was running command in Powershell 7.2.2 window, powershell command was running a different interpreter resulting in the error.

Upvotes: 1

Kylaaa
Kylaaa

Reputation: 7188

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.

Upvotes: 3

Related Questions