O'Reilly logo

PowerShell Troubleshooting Guide by Michael Shepard

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Pipeline input

The ability to accept pipeline input has been included in PowerShell since Version 1.0. There are three main ways to deal with the pipeline: $input, filters, and (fully specified) functions.

The $input automatic variable exposes an enumerator (think collection) of all the values passed in on the pipeline. An example using the $input automatic variable might look like this:

Function get-pipelineinput{
    $input | Foreach-Object {Write-Host "the object was $_"}
}

The second option, filters, are simply functions whose bodies are executed for each pipeline element. Filters use the $_ symbol to represent the current pipeline element. Here is an example of a filter script:

Filter get-reverse{
      $_.ToString().Reverse()
}

Because there is no way ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required