PoshBytes: When PowerShell Cares About Case

PoshBytes: When PowerShell Cares About Case

PowerShell usually ignores case, but its operators can tell a very different story. Learn when and how to use case-sensitive operators like -ceq and -cmatch.

This post is a companion for the video embedded below. Scroll down to see the code from the video.

https://youtube.com/shorts/STQo4wK-Ft4

The default behavior

Case-insensitive comparison

"hello" -eq "HELLO"

When you actually care about case

Case-sensitive comparison

"hello" -ceq "HELLO"

The pattern continues

Not match

"test" -ceq "TEST"

"test" -cne "TEST"

"PowerShell" -cmatch "powershell"

"PowerShell" -cnotmatch "powershell"

Explicitly ignoring case

Explicitly case-insensitive

"hello" -ieq "HELLO"

Wrap Up

• -eq, -match → ignore case
• -ceq, -cmatch → case-sensitive
• -ieq, -imatch → explicitly ignore case
• Default comparison operators ignore case
• Prefix with c to make them case-sensitive
• Prefix with i to explicitly ignore case
• Choose the operator that matches your intent, not just what works

Leave a Reply

Your email address will not be published. Required fields are marked *