Lets say I have a hashtable:
$HashTable = @{}
Now, when I want to add something to the Hashtable I usually do it like this:
$HashTable.Something = 'Something'
When I test $hashTable it will show this output:
$HashTable
Name Value
---- -----
Something Something
A Colleague of mine used Add-Member in stead:
$HashTable | Add-Member -NotePropertyName 'SomethingAddMember' -NotePropertyValue 'SomethingAddMember'
It works, but when you look at $HashTable it will still only show this:
$HashTable
Name Value
---- -----
Something Something
When I run this $HashTable.SomethingAddMember it will show up:
$HashTable.SomethingAddMember
Why is it not showing up in the HashTable itself? When I convert it to Json it's there again! How confusing can this be, or am I missing something??
$HashTable | ConvertTo-Json
{
"Something": "Something",
"SomethingAddMember": "SomethingAddMember"
}
Is it because Add-Member adds a new property to the HashTable instead of the Keys with Values? How can this happen like this?