Add-Member cmdlet invokes ScriptProperty members when adding new member
Votes from Connect: 3
Original Date Submitted: 12/4/2014 3:29:25 AM
Description:
Contact Information
Handle: Josef Nemec
Site Name: PowerShell
Feedback ID: 1045858
Frequency: Always Happens
Regression: Yes, this happens in previous released versions
Problem Description:
When calling Add-Member over an object all ScriptProperty members are being invoked (script blocks from those properties are invoked). I found it during testing on PowerShell 5 preview (from Windows 10 preview build), but it also occurs in PS 4 (tested on Windows 8.1). It seems like it occurs only with System.Management.Automation.dll 6.3.9600.17400 and newer since it works for me on 8.1 machines with version 6.3.9600.17090.
Product Studio item created by Connect Synchronizer due to creation of feedback ID 1045858 (http://connect.microsoft.com/PowerShell/feedback/ViewFeedback.aspx?FeedbackID=1045858).
Repro Steps:
Execute following commands:
$global:BaseObject = New-Object PSObject
$global:BaseObject | Add-Member ScriptProperty "Test" { Write-Host "testing message" }
$global:BaseObject | Add-Member NoteProperty "Test2" 2
"testing message" will be displayed after second Add-Member call, which indicates that property code was executed even when not called directly.
Expected Results:
ScriptProperty members shoudn't be executed during Add-Member call, but only when explicitly called, i.e. by running $BaseObject.Test in provided example.
Internal BugId: 13130
