When I execute the command:
$var = @{a=1;b=2}
in Powershell (Version 3), $var ends up with a value of {System.Collections.DictionaryEntry, System.Collections.DictionaryEntry}. Why is this happening? How can I store the values I want to store?
That's because your ISE is enumerating the collection to create the variable-treeview, and the objects returned from a
HashtableEnumeratorwhich you get from$var.GetEnumerator()areDictionaryEntry-objects.Your value (1 and 2) is stored in the
Value-property in the objects while theyKeyis the ID you used (a and b).You only need to care about this when you need to enumerate the hashtable, ex. When you're looping through every item. For normal use this is behind-the-scenes-magic so you can use
$var["a"].