Search

Hashtable Add method removes custom PSMembers added via Add-Member by Bardo33

Active

1
0
Sign in
to vote
Type: Bug
ID: 777930
Opened: 1/30/2013 8:13:36 PM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
When adding objects to a hashtable, the "Add" method removes any members which have been added via the Add-Member cmdlet.
However, when adding objects to the hashtable using the $hashtable = @{ "myKey" = $myValue } syntax, the custom PS members are retained.

This occurs in PS V2 & V3; and also possibly in V1 (not verified).
Details (expand)
How often does this happen?
Always Happens

Have you seen this problem before in this product?

Yes, this happens in previous released versions
Reproduction Steps
function Test($param1, $param2)
{
    "param1 in function: " + $param1.TestNoteProperty
    "param2 in function: " + $param2.TestNoteProperty
}

$objectWithNoteProperty = "TestObject" | Add-Member -MemberType NoteProperty -Name TestNoteProperty -Value "TestValue" -PassThru
# This retains the NoteProperty
$params = @{ "param1" = $objectWithNoteProperty }
# This DROPS the NoteProperty
$params.Add("param2", $objectWithNoteProperty)

"param1 from hashtable: " + $params["param1"].TestNoteProperty
"param2 from hashtable: " + $params["param2"].TestNoteProperty
Test @params
Expected Results
# Expected results:
param1 from hashtable: TestValue
param2 from hashtable: TestValue
param1 in function: TestValue
param2 in function: TestValue

# Actual results:
param1 from hashtable: TestValue
param2 from hashtable:
param1 in function: TestValue
param2 in function:
File Attachments
0 attachments
Sign in to post a comment.
Sign in to post a workaround.