Writing Functions with Advanced Lifecycle
suggest changeThis example shows how a function can accept pipelined input, and iterate efficiently.
begin and end are optional. process is required when the parameter uses ValueFromPipeline or ValueFromPipelineByPropertyName. Without process, the function body is an end block and only the last pipeline object is bound.
function Write-FromPipeline{
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)]
$myInput
)
begin {
Write-Verbose -Message "Beginning Write-FromPipeline"
}
process {
Write-Output -InputObject $myInput
}
end {
Write-Verbose -Message "Ending Write-FromPipeline"
}
}
$foo = 'hello','world',1,2,3
$foo | Write-FromPipeline -Verbose
VERBOSE: Beginning Write-FromPipeline
hello
world
1
2
3
VERBOSE: Ending Write-FromPipeline
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents