I’m sure that you’ve all heard that PowerShell is case insensitive, right? Most things in PowerShell are indeed case insensitive and what is case sensitive is normally expected behavior, but I’ve come across a number of things in PowerShell that are case sensitive that don’t work as I would expect them to which are listed in this blog article.
One of the first things that I discovered in PowerShell that is case sensitive that you wouldn’t
have thought would be is the
Region keyword that was introduced in PowerShell version 3:
Notice that in the previous example, placing the entire
endregion keywords in
anything other than all lower case breaks the ability to expand and compress the region so the
region keyword is definitely case sensitive.
While working with the
xSQLServer DSC resource, I
discovered that it wouldn’t work properly if a feature was specified in your DSC configuration in a
case other than upper case. I determined this was due to the
contains method being case sensitive:
$Features = 'SQLENGINE', 'SSMS', 'ADV_SSMS' $Features.Contains('SQLENGINE') $Features.Contains('SQLEngine')
There are two ways to solve this problem. Either convert what the user enters to the same case specified in your code or use the contains keyword instead:
$Features.Contains('SQLEngine'.ToUpper()) $Features -contains 'SQLEngine'
Case sensitivity isn’t exclusive to the contains method as most if not all of the methods that can be called are case sensitive as shown here where I’ll use the replace method:
$Features.Replace('SQLEngine', 'SQL') $Features.Replace('SQLENGINE', 'SQL')
Notice in the previous example that when I attempted to replace ‘SQLEngine’ with ‘SQL’, the replace did not work due to ‘SQLEngine’ not being specified in all upper case. When I did specify it in all upper case, the replace method did indeed replace the word ‘SQLENGINE’ with ‘SQL’.
This certainly isn’t an all inclusive list of everything that’s case sensitive in PowerShell, but only the things that I’ve come across that are case sensitive that I would have thought wouldn’t be.