PowerShell for Windows Admins

Oct 29 2013   4:44PM GMT

where syntax

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

This type of construction has been part of PowerShell since the very beginning:

Get-Process | where {$_.Handles -gt 500}

Get some data and use where-object to filter the data based on the value of some property. $_ represents the object on the pipeline.

PowerShell 3.0 introduced a simpler syntax

Get-Process | where Handles -gt 500

which is shorthand for

Get-Process | where -Property Handles -gt -Value 500

At which point it becomes obvious what is happening – you are comparing a property against a value. There are a whole set of comparison operators you can use in this manner – see the help file for details.

This new syntax makes life much easier when you only have a single comparison to perform – you need to use the old style syntax if you need to test on two properties.

The problem is that I don’t see this syntax being used that much. If you are using PowerShell 3.0 or above I recommend changing to the new style syntax. It does save typing.

 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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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: