The PowerShell comparison operators allow you to compare
expressions against each other. By default, PowerShell’s comparison
operators are case insensitive. For all operators where case sensitivity
applies, the –i
prefix makes this
case insensitivity explicit, while the –c
prefix performs a case-sensitive
comparison.
Windows PowerShell comparison operators | |
---|---|
Operator | Meaning |
| The equality operator: $leftValue –eq $rightValue For all primitive
types, returns When used with arrays, returns all elements
in When used with any other type, PowerShell uses that type’s
|
| The negated equality operator: $leftValue –ne $rightValue For all primitive
types, returns When used with arrays, returns all elements
in When used with any other type, PowerShell returns the
negation of that type’s |
| The greater-than-or-equal operator: $leftValue –ge $rightValue For all primitive
types, returns When used with arrays, returns all elements in When used with any other type, PowerShell returns the
result of that object’s |
| The greater-than operator: $leftValue –gt $rightValue For all primitive
types, returns When used with arrays, returns all elements in When used with any other type, PowerShell returns the
result of that object’s |
| The less-than operator: $leftValue –lt $rightValue For all primitive
types, returns When used with arrays, returns all elements in When used with any other type, PowerShell returns the
result of that object’s |
| The less-than-or-equal operator: $leftValue –le $rightValue For all primitive
types, returns When used with arrays, returns all elements in When used with any other type, PowerShell returns the
result of that object’s |
| The like (simple text matching) operator. $leftValue –like <Pattern> Evaluates the
pattern against the target, returning The like operator supports the following simple wildcard characters: ? Any single unspecified character * Zero or more unspecified characters [a-b] Any character in the range of a-b [ab] The specified characters a or b For example: |
| The negation of the like operator.
Returns |
| The match operator. “Target” –match <Regular Expression> Evaluates the regular
expression against the target, returning The For example: For more information on the details of regular expressions, see the “Regular Expression Reference” appendix. |
| The negation of the The |
| The contains operator. $list –contains $value Returns |
| The negation of the contains operator.
Returns |
| The type operator. Returns |
| The negation of the type operator. Returns |
3.16.147.124