Closed
Description
Currently you can create functions / cmdlets with parameters with ValueFromPipeline or ValueFromPipelineByPropertyName, but if you forget the process { } block, only the last pipeline object will be processed by the cmdlet, instead of all of them, resulting in unexpected behavior that can slip through the cracks unnoticed until you pipe a batch of objects to the commandlet and realize that it only processed one of them. PSScriptAnalyzer should default to warning developers to use the process { } block when they use ValueFromPipeline or ValueFromPipelineByPropertyName attributes in a function / cmdlet.
Function Broken
{
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeline)]
[int]
$ToPrint
)
$ToPrint
}
Function Correct
{
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeline)]
[int]
$ToPrint
)
process
{
$ToPrint
}
}
1..10 | Broken
# only 10 was output. PSScriptAnalyzer ought to be catching this
1..10 | Correct
# 1 - 10 were each output, as you would expect