PowerShell for Windows Admins

May 8 2012   1:22PM GMT

Scripting Games 2012 comments: #15 pipelines

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: