Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shorthand for PowerShell's `ForEach -Parallel`

In a PowerShell workflow, the following is valid:

$strings='one','two','three'
foreach -parallel($string in $strings)
{
    "Hello: $string"
}

A shorhand way of writing this (without the parallel piece) would be:

$strings='one','two','three'
$strings | `
%{
    "Hello: $_"
}

Is there a way to use the shorthand version, specifying that it should be run in parallel?

like image 876
JohnLBevan Avatar asked Mar 28 '26 18:03

JohnLBevan


1 Answers

Not that I can see.

% is a default alias for ForEach-Object which is a core cmdlet. foreach -parallel within workflows is a workflow activity that is separate form the cmdlet and only callable within workflows. In this case, you would need to set an alias to foreach -parallel in your workflow to call the workflow activity - but manipulating aliases is disallowed within workflows (source).

like image 58
Kohlbrr Avatar answered Apr 03 '26 17:04

Kohlbrr