New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select-Object -ExpandProperty quietly discards instance members #7937

mklement0 opened this Issue Oct 3, 2018 · 0 comments


None yet
2 participants

mklement0 commented Oct 3, 2018

Follow-up from #7768

If you use -ExpandProperty with a property whose value happens to be an object instance members (ETS members added with -Add-Member), these members are no longer present in the value returned.

Note: The behavior only surfaces if the object is not an instance of [psobject] - whether a true custom object ("property bag") or an incidental [psobject] wrapper (see #5579).

@PetSerAl discovered this problem in the context of #7768 and explains it as follows:

In v2 extra properties were linked to PSObject wrapper. So two PSObjects wrapping the same underlying object can have different set of extra properties. In v3 properties now linked to underlying object (with some exceptions), but not to PSObject wrapper. But in the process PowerShell devs decided to keep/grant Select-Object -ExpandProperty ability to create independent PSObject wrappers, which links properties to themselves rather than to underlying objects.
Although, I do not think Select-Object should really do this. I do not see reasons why it use/have this ability in the first place (compatibility? maybe).

Steps to reproduce

$v = [datetime]::now; $v | Add-Member myProp myPropValue
# This should retrieve the original $v value, via Select-Object -ExpandProperty
 $vToo = [pscustomobject] @{ prop = $v } | Select-Object -ExpandProperty prop

Expected behavior


That is, the .myProp instance member should still be present.

Actual behavior


That is, the .myProp instance member was discarded.

Environment data

PowerShell Core v6.1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment