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.

Views: 2345

Related

Combining more than one filter in where-object filtering in PowershellCombining more than one filter in where-object filtering in Powershell to filter results returned fr...How To Write Custom Powershell Cmdlet - Part 1How to write custom powershell cmdletHow to write Custom Powershell Cmdlet - Part 3How to write custom output formatting file for custom powershell Cmdlet.How To Write Custom Powershell Cmdlet - Part 2How To Write Custom Pwershell Cmdlet - Part 2. How to write snap-in for powershell Cmdlet to registe...Windows Powershell command alias name listList of Windows powershell command alias names

Powered by BlogEngine.NET 1.5.1.7
Theme by Naveen Kohli

By Categories