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: -
eqand-ne - Like and not like:
-likeand-notlike - Greater than and greater than or equal to:
-gtand-ge - Less than and less than or equal to:
-ltand-le - Contains and not contains:
-containsand-notcontains - In and not in:
-inand-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...