Selecting strings and case sensitivity

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


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.

Tags:

Powershell