In powershell how does one create a hashmap that contains a string as the key and a list of strings as the values?
For example, in Java, the following can be done:
Map<String, List<String> myMap = new HashMap<String, List<String>();
Does powershell contain this capability?
I've tried:
$myMap = @{ [string], New-Object Collections.Generic.List[string] }
But this didn't work.
$myMap = @{ "Michigan"="Detroit"; "California" = "Sacremento","Hollywood";"Texas"="Austin" }
Note how California has two values assigned to it's key. Also note how you will run into trouble if you ever try to export this to csv, the enumerator skips over the array value and just inserts "System.Object[]" into the csv file, probably as it should.
Update
To dynamically update the list,
$myMap.California += "Compton"
I figured it out.
$myList = New-Object Collections.Generic.List[string]
$myList.Add("one")
$myList.Add("two")
$myList.Add("three")
$myHash = @{ }
$myHash.Add("list", $myList)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With