When using the ForEach-Object function, is there a way to provide a function instead of a code block.
This would enable me to simplify this:
@(1, 2, 3, 4) | % { Add-One $_ }
to this, or similar:
@(1, 2, 3, 4) | % Add-One
For completeness here is the current definition of the Add-One function
function Add-One($Number) {
return $Number + 1
}
It's easy to write a function with process to do something similar, like so:
@(1, 2, 3, 4) | Add-One
However, this means that you have to re-implement the loop and ValueFromPipeline for each function instead of reusing what ForEach-Object already provides. So in short is there a way to use a scalar function with ForEach-Object that avoids wrapping it in a Code Block?