I was just wondering if you can modify the key in a hashtable. I have been able to successfully modify the value attached to the key but have been unable to modify the actually key.
$names = @{Tree = "1"; Forest = "2"}
Take for example the code above, I'd like to change the "Tree" to something other than tree.
No, you cannot do this directly. Instead,
you will need to make a new key that has the same value as "Tree" and then delete the "Tree" key when you are done. Below is a demonstration:
PS > $names = @{Tree = "1"; Forest = "2"}
PS > $names.NewKey = $names.Tree
PS > $names.Remove("Tree")
PS > $names
Name Value
---- -----
NewKey 1
Forest 2
PS >
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