Case-Sensitive Hash Tables

by Jun 13, 2011

PowerShell hash tables are, by default, not case sensitive:

PS > $hash = @{}
PS > $hash.Key = 1
PS > $hash.keY = 2
PS > $hash.KEY
2

If you need case-sensitive keys, you can create the hash table this way:

PS > $hash = New-Object system.collections.hashtable
PS > $hash.Key = 1
PS > $hash.keY = 2
PS > $hash.KEY
PS > $hash

Name                           Value
----                           -----
keY                            2
Key                            1

 

Twitter This Tip!
ReTweet this Tip!