Comparison operators in Where-Object in Powershell

Where-Object is heart of filtering results generated by Get-* commands in Powershell. One of the parameters that Where-Object takes is FilterScript where you can specify the comparison conditions for a given object. This parameters evaluates to true or false depending on comparison result. For example you may want to filter result based on some preoprty or value being less than or greater than certain value. First reaction you will have is to say that you can use operator like < or >. Well, that does not work in FilterScript. Following is list of comparison operators that are used in Powershell scripting.

Operator Meaning
-eq is equal to
-ne Is not equal to
-lt Is less than
-le Is less than or equal to
-gt Is greater than
-ge Is greater than or equal to
-like Is like (wildcard comparison for text)
-notlike Is not like (wildcard comparison for text)
-contains Contains
-notcontains Does not contain

When you are using comparison operator for text comparison, the operators are case-insensitive by default.

blog comments powered by Disqus
$1.99 Website Hosting- Go Daddy Proud Sponsor of Danica Patrick

Smart Phones Poll

What smart phone do you currently own?





Show Results

Month List

Powered by BlogEngine.NET 2.0.0.49
Theme by Naveen Kohli