Summary: Add a key-value pair to the first position in an ordered dictionary.
How can I use Windows PowerShell to add a key-value pair to the first position in an ordered dictionary?
Use the Insert method, which takes an index (starting with zero), a key, and a value.
To add color = blue to the ordered dictionary in the $od variable:
PS C:> $od
Name Value
—- —–
shape rectangle
distance 50
PS C:> $od.Insert(0, “color”, “blue”)
PS C:> $od
Name Value
—- —–
color blue
shape rectangle
distance 50
0 comments