Comparison Operators
The following operators are all Case-Insensitive by default:
-eqEqual-neNot equal-geGreater than or equal-gtGreater than-ltLess than-leLess than or equal-likeWildcard comparison-notlikeWildcard comparison-matchRegular expression comparison-notmatchRegular expression comparison-replaceReplace operator-containsContainment operator-notcontainsContainment operator-inLike –contains, but with the operands reversed.(PowerShell 3.0)-notinLike –notcontains, but with the operands reversed.(PowerShell 3.0)
To perform a Case-Sensitive comparison just prefix any of the above with "c" for example -ceq for case-sensitive Equals or -creplace for case-sensitive replace.
Similarly prefixing with "i" will explicitly make the operator explicitly case insensitive. It seems likely that these short names such as -eq were chosen for operators instead of symbols (= / <> etc) to allow for these case sensitive options.
Types
-isIs of a type-isnotIs not of a type-asAs a type, no error if conversion fails
Logical operators
-andLogical And-orLogical Or-xorLogical exclusive Or-notlogical not!logical not
Bitwise operators
-bandBitwise and-borBitwise or-bXorBitwise OR (exclusive)-bNotBitwise NOT-shlShift bits left (PowerShell 3.0)-shrShift bits right – preserves sign for signed values.(PowerShell 3.0)
Format Operator
"format_string" -f Object1, Object2,...
The format_string is in the form: {0,-5} {1,-20} {2,-10}
In each set of braces, the first number, before the comma refers to the column. The second number, after the comma determines the padding (how many characters) If the second number is negative, it not only pads the element, but aligns it vertically. Optionally the second number can be used for formatting :hh :mm :C :p
When applied to an array, comparison operators will work as a filter returning all the values which match.
Filters
A PowerShell Filter will accept the following operators
-eq-ne-ge-gt-lt-le-like-notlike-approx-bor-band-recursivematch
Notice that this list misses out several useful operators such as -match and -contains but those can still be used by piping to a Where-Object clause: ... | Where {$_.name –match 'value'}
Examples
| |
Related PowerShell Cmdlets:
- if - Conditionally perform a command.
- Assignment Operators ( $variable = X, $variable += Y )
- PowerShell Regular Expressions
- Format-Table