Shorthand for PowerShell `ForEach -Parallel`
The following is valid in a PowerShell workflow:
$strings='one','two','three'
foreach -parallel($string in $strings)
{
"Hello: $string"
}
Correct way of writing this (no parallel part):
$strings='one','two','three'
$strings | `
%{
"Hello: $_"
}
Can I use a shorthand version specifying that it should run in parallel?
source to share
Not what I see.
%
is the default alias for ForEach-Object
which is the main cmdlet. foreach -parallel
in workflows is a workflow operation, which is a separate form of a cmdlet and can only be invoked in workflows. In this case, you will need to set an alias foreach -parallel
in the workflow in order to invoke the workflow operation, but manipulating aliases is prohibited within workflows ( source ).
source to share