PS 1.0 Comparison and Containment Operators

Windows PowerShell Comparison Operators

These operators work both with string and number based values assuming that you are comparing like with like (it is not meaningful, for example, to compare a string with numerical value). In terms of working with strings and characters, both case-sensitive and insensitive operators are supported.

 

Operator Description
-eq Equal to (case insensitive)
-ieq Equal to (case insensitive)
-ceq Equal to (case sensitive)
-ne Not equal to (case insensitive)
-ine Not equal to (case insensitive)
-cne Not equal to (case sensitive)
-gt Greater than (case insensitive)
-igt Greater than (case insensitive)
-cgt Greater than (case sensitive)
-ge Greater than or equal to (case insensitive)
-ige Greater than or equal to (case insensitive)
-cge Greater than or equal to (case sensitive)
-lt Less than (case insensitive)
-ilt Less than (case insensitive)
-clt Less than (case sensitive)
-le Less than or equal to (case insensitive)
-ile Less than or equal to (case insensitive)
-cle Less than or equal to (case sensitive)

 

 

Windows PowerShell Containment Operators

In addition to the comparison operators, a set of operators referred to as containment operators are provided for the purpose of identifying whether an array or collection contains a specific value. The containment operators provided by PowerShell are listed in the following table. As with the comparison operators, both case sensitive and insensitive options are provided.

 

Operator

Description

-contains

Group of values in left hand operand contains value specified in right hand operand (case insensitive)

-icontains

Group of values in left hand operand contains value specified in right hand operand (case insensitive)

-ccontains

Group of values in left hand operand contains value specified in right hand operand (case sensitive)

-notcontains

Group of values in left hand operand does not contain value specified in right hand operand (case insensitive)

-inotcontains

Group of values in left hand operand does not contain value specified in right hand operand (case insensitive)

-cnotcontains

Group of values in left hand operand does not contain value specified in right hand operand (case sensitive)

 

 

Reference: Windows PowerShell 1.0 Comparison and Containment Operators

Leave a Reply

Your email address will not be published. Required fields are marked *