description | ms.date | ms.topic | title |
---|---|---|---|
Use process block for command that accepts input from pipeline. |
06/28/2023 |
reference |
UseProcessBlockForPipelineCommand |
Severity Level: Warning
Functions that support pipeline input should always handle parameter input in a process block. Unexpected behavior can result if input is handled directly in the body of a function where parameters declare pipeline support.
Function Get-Number
{
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeline)]
[int]
$Number
)
$Number
}
PS C:\> 1..5 | Get-Number
5
Function Get-Number
{
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeline)]
[int]
$Number
)
process
{
$Number
}
}
PS C:\> 1..5 | Get-Number
1
2
3
4
5