Search

PowerShell Pipelines

The command piping is a very useful featurs and piping can take the output of one command as the input for another command. The pipe symbol is a vertical bar (|). To pipe commands together, place a pipe symbol between each command on the command line. You may familiar with the "dir" command in DOS, which is used to list the contents of a directory. If the directory you are listing has many contents, you can pipe the output of the "dir" command to "more" to show the output page by page.

C:\WINDOWS\system32>dir | more

Now the contents of the directory will be listed page by page, as shown below.

Command prompt pipeline

 

Pipelines are available with PowerShell also but unlike other shells, in PowerShell the result is passed from one cmdlet to next cmdlet as an object, not as a string. Each command in a pipe is separated by the pipe character (|). Following pipeline example, output from "Get-ChildItem" cmdlet is piped into Out-Host command for display with "-Paging" option to display the contents page by page.

PS> C:\ Get-ChildItem | Out-Host -Paging

The output of the above command is shown below.

PowerShell pipeline example

Related Tutorials