Selecting strings and case sensitivity
I am trying to filter for an object that has a Title field, and I want to ignore case. Is there a way to make sure case sensitivity if turned off?
| Where-Object {$_.Title -like "myString"}
PowerShell is fundamentally case insensitive (e.g. "HEy" -like "hey"
is True
).
If you want to use the case sensitive version of like
, use -clike
.
By default case sensitivity is off:
PS> 'test','TEST','TeSt','notest' | ? { $_ -like 'test' }
test
TEST
TeSt
From documentation:
By default, all comparison operators are case-insensitive. To make a comparison operator case-sensitive, precede the operator name with a
"c"
. For example, the case-sensitive version of"-eq"
is"-ceq"
. To make the case-insensitivity explicit, precede the operator with an"i"
. For example, the explicitly case-insensitive version of"-eq"
is"-ieq"
.
For more information run help about_comparison_operators