PowerShell pipeline-input

In order to receive objects in a pipeline, the receiving cmdlet must have a parameter that accepts pipeline input. You can use a Get-Help command with the Full or Parameter parameters to determine which, if any, of a cmdlet’s parameters accepts pipeline input.

In the Get-Help default display, the “Accepts pipeline input” item appears in a table of parameter attributes. This table is displayed only when you use the Full or Parameter parameters of the Get-Help cmdlet.

For example, to determine which of the parameters of the Start-Service cmdlet accepts pipeline input, type:

get-help start-service -full get-help start-service -parameter *

For example, the help for the Start-Service cmdlet shows that the Name and InputObject parameters accept pipeline input (“true”). All other parameters have a value of “false” in the “Accept pipeline input?” row.

-name <string[]> Specifies the service names for the service to be started. The parameter name is optional. You can use “-Name” or its alias, “-ServiceName”, or you can omit the parameter name.

Required? true Position? 1 Default value –> Accept pipeline input? true (ByValue, ByPropertyName) Accept wildcard characters? true

-inputObject <ServiceController[]> Specifies ServiceController objects representing the services to be started. Enter a variable that contains the objects or type a command or expression that gets the objects.

Required? false Position? named Default value –> Accept pipeline input? true (ByValue) Accept wildcard characters? false

This means that you can send objects (PsObjects) through the pipeline to the Where-Object cmdlet and Windows PowerShell will associate the object with the InputObject parameter.

Methods of Accepting Pipeline Input

Cmdlets parameters can accept pipeline input in one of two different ways:

ByValue: Parameters that accept input “by value” can accept piped objects that have the same .NET type as their parameter value or objects that can be converted to that type.

For example, the Name parameter of Start-Service accepts pipeline input by value. It can accept string objects or objects that can be converted to strings.

ByPropertyName: Parameters that accept input “by property name” can accept piped objects only when a property of the object has the same name as the parameter.

For example, the Name parameter of Start-Service can accept objects that have a Name property.

(To list the properties of an object, pipe it to Get-Member.)

Some parameters can accept objects by value or by property name. These parameters are designed to take input from the pipeline easily.