It looks like there are different kinds of hashtables in PowerShell, ones that are case sensitive and ones that are not. When defining a hashtable as the following it's not case sensitive:
$ht = @{ "Test" = "HI" }
$ht.Contains("test") #returns true, even with key name lowercase
True
$ht.ContainsKey("test") #returns true, even with key name lowercase
True
$ht.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Hashtable System.Object
However, if you define it as such it is case sensitive:
$ht_caseSensitive = New-Object System.Collections.Hashtable
$ht_caseSensitive.Add("Test", "HI")
$ht_caseSensitive.Contains("test") # returns false, since it's all lowercase
False
$ht_caseSensitive.ContainsKey("test") # returns false, same with contains key function
False
$ht_caseSensitive.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Hashtable System.Object
However, as shown in the GetType()
output, I can't seem to find a way to differentiate between these objects.
- Why is one case sensitive and the other is not?
- Is there any way I can differentiate between them when it's important to know whether I'm dealing with a hashtable that's case sensitive or not?