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?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With