0
votes

When I debug below lines of code in VS code it works fine.But, When this code executes in azure devops (release pipeline azure powerShell task), I get below task error. azure powerShell Taskversion = ~ 5.* Is this version specific?

(Measure-Command {
        1..200 | ForEach-Object -Parallel $testScript -ThrottleLimit 5
    }).TotalMinutes

Error: 2020-12-16T11:25:36.6181969Z + $timeTaken = (Measure-Command { 2020-12-16T11:25:36.6183027Z + ~~~~~~~~~~~~~~~~~ 2020-12-16T11:25:36.6184374Z + CategoryInfo : MetadataError: (:) [Measure-Command], ParameterBindingException 2020-12-16T11:25:36.6185735Z + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.MeasureCommandCommand

1
Looks like issue is with ForEach-Object command. Below code throws "Parameter set cannot be resolved using the specified named parameters" error. Code: 1..100 | ForEach-Object -Parallel {Write-Host "Test"} -ThrottleLimit 5suraj_123

1 Answers

0
votes

Parameter set cannot be resolved using the specified named parameters

I could reproduce this issue. The root cause of this issue is that PowerShell 7 supports the command: ForEach-Object -Parallel.

This issue is related with the PowerShell Version.

Here is the doc about the Powershell 7 information:

Pipeline parallelization with ForEach-Object -Parallel

In azure devops, WindowsPowerShell 5.1 is used by default.

To solve this issue, you need to select the option: Use PowerShell Core in Azure PowerShell Task -> Advanced:

enter image description here

Then it will use the Powershell 7 in the agent and the command can be executed successfully.