When comparing numbers, each of the operators -ge (greater than or equal to), -gt (greater than), -le (less than or equal to), and -lt (less than) are simple to use:
1 -ge 1 # Returns true 2 -gt 1 # Returns true 1.4 -lt 1.9 # Returns true 1.1 -le 1.1 # Returns true
String comparison with operators follows the generalized pattern 0123456789aAbBcCdD... rather than basing on a character table (such as ASCII):
- Cultural variants of characters, for example, the character å, fall between A and b in the list
- Other alphabets, for example Cyrillic or Greek, come after the Roman alphabet (after Z)
Comparison can be culture sensitive when using commands such as Sort-Object with the Culture parameter, but comparisons are always based on en-US when using the operators:
'apples' -lt 'pears' # Returns true 'Apples' -lt 'pears' # Returns true 'bears' -gt 'Apples' # Returns true
Or when using case-sensitive comparison:
'bears' -gt 'Bears' # False, they are equal to one another 'bears' -clt 'Bears' # True, b before B