Pipeline input
Using the Parameter
attribute to set either ValueFromPipeline
or ValueFromPipelineByPropertyName
sets a parameter up to fill from the input pipeline.
The pipeline is a complex topic and requires a background in the use of named blocks. Named blocks, along with a broader set of examples for pipeline usage, are available in Chapter 17, Scripts, Functions, and Script Blocks.
About ValueFromPipeline
ValueFromPipeline
allows the entire object to be passed into a parameter from an input pipeline. The following function implements an InputObject
parameter, which accepts pipeline input by using the ValueFromPipeline
property of the Parameter
attribute:
function Get-InputObject {
[CmdletBinding()]
param (
[Parameter(Mandatory, ValueFromPipeline)]
$InputObject
)
process {
'Input object was of type {0}' -f @(
$InputObject.GetType().FullName
)
}
}
Remember that values read from an...