Windows PowerShell - Pipeline Symbol (|) or (¦)PowerShell Scripting - Pipeline Symbol (|) or (¦)Pipelining could almost be described as PowerShell's signature tune. Windows PowerShell encourages you to join two statements so that the output of the first clause, becomes the input of the second clause. If it helps to streamline your task, you can have more than one join per statement, thus the output of the second clause, becomes the input of the third element. To separate these individual clauses, Microsoft chose the pipe symbol, '|' sometimes called the bar key. To give you a physical analogy, think of an oil pipeline with lots of cylinders joined together with hollow ring seals. Or better still, an assembly line to produce a bottle of beer!
One common use of pipelining is the 'Where' clause, for example: I also use the pipe for research, my technique is to place '|' between the object I am investigating and get-Member. For example, get-service | get-Member. Windows PowerShell Pipeline Topics
Pipeline (|) or (¦) - Display ConfusionWhen typed in notepad the pipeline symbol looks like a solid vertical bar |, but when typed at the Windows PowerShell PS> prompt, it looks like ¦. On my keyboard the key in question is next to the Z, however I have seen keyboards where the key is next to numeric 1 on the top row. Once you press the correct key, you get a pipe or bar symbol like this: |. To be crystal clear, this pipe symbol, | corresponds to ASCII 124. N.B this not ASCI 0166. Test by holding down the Alt key, then type the number 124 on the numeric pad, finally, let go of the Alt key. Pipeline ExamplesHere are four examples showing how to join two or more clauses to form a continuous PowerShell production line. Check the logic. See how the output from the first clause becomes the input for the second statement. Example 1:
get-Process. Let us discover the members and properties Example 2: Example 3: Example 4: The last example has two pipe symbols. You may observe that either 'where-object', or plain 'where', work equally well. Also, -gt means greater than. $_ Placeholder in the current pipeline.$_ is
special PowerShell placeholder, which references a property in the current pipeline. In
the above example, that current property is .handlecount, hence, $_.handlecount. I feel certain that $_ is a PowerShell feature that you will employ in numerous scripts, thus it is worth memorizing the
rhythm of the command: get-help * | where { $_.name -match "get" } | ft name, synopsis -autosize Another example of $_ The idea is to list all PowerShell items which have the word "Object" in their synopsis. Trace how the example is constructed from three clauses separated by two | pipes.
˚
Summary of the Pipeline Symbol |Windows PowerShell's SignatureWhat makes PowerShell modular is the ability to pipe the output of the first command so that it becomes the input of the second command. When you need to refine a script | filter the output | or format the display, then call for the pipe symbol (bar key) to join each statement, and thus construct your pipeline of PowerShell commands. The confusion of the pipeline symbol (|) is because the character corresponding to ASCII 124 displays differently in Notepad compared with when typed at the PowerShell command line. Once you have the correct symbol you will find numerous uses to combine, or pipeline, two or three clauses to make a punchy PowerShell command. See Also• Windows PowerShell Home • Introduction • Cmdlets • Exchange 2007 • Profile.ps1 • $_.Pipeline If you see an error of any kind, do let me know. Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit. *
|
|||||