MicrosoftDocs / PowerShell-Docs

The official PowerShell documentation sources
https://learn.microsoft.com/powershell
Creative Commons Attribution 4.0 International
1.93k stars 1.55k forks source link

`Select-Object` should be explicit that the input object can be modified #11198

Closed SteveL-MSFT closed 2 weeks ago

SteveL-MSFT commented 2 weeks ago

Prerequisites

Links

Summary

The Select-Object docs do not indicate that there are cases where the input object may be modified which can be surprising to users. As the WG-Cmdlets has made a decision to NOT change this behavior as we believe it would likely break folks, we need to document this explicitly.

Details

Suggested Fix

Add details to the docs on when the input object can be modified. Add example on how to get the same behavior as ExpandProperty by simply creating a new PSObject "manually" instead of using Select-Object

sdwheeler commented 2 weeks ago

I will add examples to show the behavior and how to work around the behavior

function Test-Select {
    [PSCustomObject]@{
        "name"="admin1"
        "children"=[PSCustomObject]@{
            "name"="admin2"
        }
    }
}

$obj = Test-Select

New-Object PSObject -Property @{Country = $obj.name; Children=$obj.Children}