问题
from another application I have key-value pairs which I want to use in my script.
But there they have e.g. the keys "a" and "A" - which causes an Error double keys aren't allowed.
$x = @{ "a" = "Entry for a"; "A" = "S.th.else for A" }
What can I do as I would need both or none?
Thanks in advance,
Gooly
回答1:
By default PowerShell Hash tables are not case sensitive. Try this
$h = new-object System.Collections.Hashtable
$h['a'] = "Entry for a"
$h['A'] = "S.th.else for A"
$h[0] = "Entry for 0"
$h[1] = "Entry for 1"
$h
Or this (depending on the syntax that you prefer)
$hash = New-Object system.collections.hashtable
$hash.a = "Entry for a"
$hash.A = "S.th.else for A"
$hash.0 = "Entry for 0"
$hash.1 = "Entry for 1"
$hash.KEY
$hash
回答2:
You can create a case-sensitive powerhsell hash table using System.Collections.Hashtable
$x = New-Object System.Collections.Hashtable
$x['a']="Entry for a"
$x['A']="S.th.else for A"
来源:https://stackoverflow.com/questions/24054147/powershell-hash-tables-double-key-error-a-and-a