the follow code works fine in powershell 4.0 , earlier. if run on version 5.0.10240.16384 on latest windows 10 build fields don't populate in new object ($a). bug or has changed?
add-type @" public struct testuser { public string first; public string last; } "@; $a = new-object testuser -property @{ first = "joe" last = "smith"}; version 4.0 , earlier results:
$a.first -eq "joe" $a.last -eq "smith" version 5.0
$a.first -eq $null $a.last -eq $null version 5 get-member
typename: testuser name membertype definition ---- ---------- ---------- equals method bool equals(system.object obj) gethashcode method int gethashcode() gettype method type gettype() tostring method string tostring() first property string first {get;set;} last property string last {get;set;} edit: i've submitted bug regarding microsoft based on being breaking change (if change) impact many existing scripts. update question if there updates on bug report. i'm still looking feedback if has run across in v5 might suggest desired/changed behavior. glad try other testing on v5 if curious , doesn't have access win 10 machine.
i've gotten verification powershell team member bug related missing "unbox" call. workaround use class instead of struct if possible. mentioned struct provides little benefit in powershell, powershell box struct.
Comments
Post a Comment