Changes

Jump to: navigation, search

Windows PowerShell 1.0 Pipes and Redirection

1,544 bytes added, 21:00, 1 December 2008
New page: Features of PowerShell which will no doubt be familiar to users of UNIX and Linux based shell environments are pipes and redirection. The primary purpose of pipes is to chain commands toge...
Features of PowerShell which will no doubt be familiar to users of UNIX and Linux based shell environments are pipes and redirection. The primary purpose of pipes is to chain commands together, passing the output from one command through to the next command. Redirection, on the other hand, allows the output from a command to be sent to a file. Unfortunately, whilst UNIX and Linux based shells allow input to be redirected to a commands (such as input from the keyboard), version 1.0 of PowerShell does not yet support this feature.

== PowerShell Pipes ==

Pipelines in PowerShell are essential a sequence of commands in which the result of each command is passed through the the subsequent command for processing. One point to note is that, unlike other shell environments, the result passed from one command to the next need not be a string, in fact it can be any type of object. Each command in a pipe is separated by the pipe character (|).

A common example of the use of pipes involves piping output from a command through to a second command which in turn formats that output. In the following example, the output from the ''Get-Childitem" command is piped through to the ''format-table '' command:

<pre>
PS C:\Users\Administrator> get-childitem mydata.txt | fl


Directory: Microsoft.PowerShell.Core\FileSystem::C:\Users\Administrator



Name : mydata.txt
Length : 30
CreationTime : 11/14/2008 12:33:23 PM
LastWriteTime : 12/1/2008 12:39:44 PM
LastAccessTime : 11/14/2008 12:33:23 PM
VersionInfo :
</pre>

Navigation menu