Search code examples
powershellcomparison-operators

How to make `-eq` case sensitive in Powershell?


Powershell's about_Comparison_Operators page in its "Common features" section starts with:

By default, string comparisons are case-insensitive.

How do I change that default?


Solution

  • Powershell language specification 3.0 section 7.8 states:

    Some comparison-operators (written here as -op) have two variants, one that is case sensitive (-cop), and one that is not (-iop). The -op version is equivalent to -iop. Case sensitivity is meaningful only with comparisons of values of type string. In non-string comparison contexts, the two variants behave the same.

    So, as I suspected in my comment, "By default" in the documentation most likely refers to non-prefixed operator variants rather than some Powershell setting.

    I.e. there is no way to make -eq to be case-sensitive.

    The documentation referenced in the question since have been reworded to remove the confusing language, supporting this understanding.