Skip to content

Files

Latest commit

 

History

History
66 lines (50 loc) · 1.01 KB

UseProcessBlockForPipelineCommand.md

File metadata and controls

66 lines (50 loc) · 1.01 KB

Pattern: Missing use of process block for pipeline command

Issue: -

Description

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.

Examples

Example of incorrect code:

Function Get-Number
{
	[CmdletBinding()]
	Param(
		[Parameter(ValueFromPipeline)]
		[int]
		$Number
	)
	
	$Number
}

Result

PS C:\> 1..5 | Get-Number
5

Example of correct code:

Function Get-Number
{
	[CmdletBinding()]
	Param(
		[Parameter(ValueFromPipeline)]
		[int]
		$Number
	)
	
	process
	{
		$Number
	}
}

Result

PS C:\> 1..5 | Get-Number
1
2
3
4
5

Further Reading