PowerShell introduces an object pipelining model, which allows you to send whole objects down through the pipeline to consuming commandlets or (at least) the output. In contrast to classical string-based pipelining, information in piped objects don't have to be on specific positions. Commandlets can declare to interact with Objects from the pipeline as input, while return values are sent to the pipeline automatically.
In most cases, the input of the pipeline will be an array of objects. Although the behavior of the PROCESS{}
block may seem similar to the foreach{}
block, skipping an element in the array requires a different process.
If, like in foreach{}
, you used continue
inside the PROCESS{}
block, it would break the pipeline, skipping all following statements including the END{}
block. Instead, use return
- it will only end the PROCESS{}
block for the current element and move to the next.
In some cases, there is a need to output the result of functions with different encoding. The encoding of the output of the CmdLets is controlled by the $OutputEncoding
variable. When the output is intended to be put into a pipeline to native applications, it might be a good idea to fix the encoding to match the target $OutputEncoding = [Console]::OutputEncoding
Additional references:
Blog article with more insight about $OutputEncoding
https://blogs.msdn.microsoft.com/powershell/2006/12/11/outputencoding-to-the-rescue/