Categories

Scripting Games 2012 comments: #15 pipelines

There are a few comments to make about using the pipeline but one of the obvious issues I saw from the games was this type of approach

 

$p = Get-Process
$p | where {$_.Name -like "powershell*"}

 

The only time this is valid is if you need to access exactly the same data later in your script.

In all other cases use

Get-Process | where {$_.Name -like "powershell*"}

 

if you want to split the lines to make it more readable the pipe symbol acts as a line continuation character so

Get-Process |
where {$_.Name -like "powershell*"}

is just as valid

PowerShell is all about the pipeline – use it to your advantage

Leave a Reply