Comparison operators
Comparison operators can be used to compare two values. PowerShell has a wide variety of comparison operators, which are as follows:
- Equal to and not equal to: -
eq
and-ne
- Like and not like:
-like
and-notlike
- Greater than and greater than or equal to:
-gt
and-ge
- Less than and less than or equal to:
-lt
and-le
- Contains and not contains:
-contains
and-notcontains
- In and not in:
-in
and-notin
Values can be directly compared to one another in PowerShell using the equality operators.
eq and ne
The -eq
(equal to) and -ne
(not equal to) operators perform exact (and, by default, case-insensitive) comparisons. In the following example, true
is returned for each of the comparisons:
1 -eq 1
'string' -eq 'string'
Similarly, -ne
(not equal) will return true
for each of the following:
20 -ne 100
'this' -ne 'that'
When working with comparison expressions, it is important to consider the left...