I’m a novice in PowerShell.
Recently I encountered a problem about how to cascade commands or functions. I’ve found 2 ways:
CMD_B (CMD_A ($x))
$x | CMD_A | CMD_B
But, what’s the difference between the above 2 ways?
For example, the results of Write-Output (Get-Process)
and Get-Process | Wirte-Output
look the same. Are there different details hidden?
I’ve searched the doc about grouping-operator ()
and Pipeline operator |
, and find:
Piping grouped expressions
When used as the first segment of a pipeline, wrapping a command or expression in parentheses invariably causes enumeration of the expression result. If the parentheses wrap a command, it’s run to completion with all output collected in memory before the results are sent through the pipeline.
Grouping an expression before piping also ensures that subsequent object-by-object processing can’t interfere with the enumeration the command uses to produce its output.
But I don’t quite understand it. Maybe it’s because I lack the basic knowledge of pipelines.
Thanks in advance.