PowerShell Working with the PowerShell pipeline Basic Pipeline Support in Functions


This is an example of a function with the simplest possible support for pipelining.
Any function with pipeline support must have at least one parameter with the ParameterAttribute ValueFromPipeline or ValueFromPipelineByPropertyName set, as shown below.

function Write-FromPipeline {
        [Parameter(ValueFromPipeline)]  # This sets the ParameterAttribute
    Write-Host $Input

$foo = 'Hello World!'

$foo | Write-FromPipeline


Hello World!

Note: In PowerShell 3.0 and above, Default Values for ParameterAttributes is supported. In earlier versions, you must specify ValueFromPipeline=$true.