Summary: Learn how to perform a case-sensitive comparison in Windows PowerShell.
I need to compare two strings while taking case sensitivity into account. I try using -eq, but it does not work.
How can I use Windows PowerShell to perform a case-sensitive comparison?
Use the -ceq operator instead of -eq. Here are two examples that compare the results of -eq and -ceq:
PS C:\> 'scripting guys' -eq 'Scripting Guys'
True
PS C:\> 'scripting guys' -ceq 'Scripting Guys'
False
PS C:\>
Hi Scripting Guys
I've programmed quite a bit in other languages but I'm fairly new to PowerShell. I'm aware of the case sensitive versions of the comparison operators but I'm nervous about some results..
I assumed that PowerShell used ASCII (Unicode) values when doing string comparisons so I expected
'abc' -clt 'ABC'
to result in False - but it didn't
This makes some intuitive sense (lower must be smaller than upper - right?) but it doesn't make sense...