Title: Select-Object modifies input objects when using both -ExpandProperty and -Property · Issue #7768 · PowerShell/PowerShell · GitHub
Open Graph Title: Select-Object modifies input objects when using both -ExpandProperty and -Property · Issue #7768 · PowerShell/PowerShell
X Title: Select-Object modifies input objects when using both -ExpandProperty and -Property · Issue #7768 · PowerShell/PowerShell
Description: Select-Object should never modify its input objects, but it does, when using both the -ExpandProperty and -Property parameters. This behavior is documented, but wrong. Steps to reproduce $NestedObjects = [pscustomobject]@{a=1; b=[pscusto...
Open Graph Description: Select-Object should never modify its input objects, but it does, when using both the -ExpandProperty and -Property parameters. This behavior is documented, but wrong. Steps to reproduce $NestedObj...
X Description: Select-Object should never modify its input objects, but it does, when using both the -ExpandProperty and -Property parameters. This behavior is documented, but wrong. Steps to reproduce $NestedObj...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/7768
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Select-Object modifies input objects when using both -ExpandProperty and -Property","articleBody":"`Select-Object` should never modify its input objects, but it does, when using both the `-ExpandProperty` and `-Property` parameters.\r\n\r\nThis behavior is documented, but wrong.\r\n\r\nSteps to reproduce\r\n------------------\r\n\r\n```powershell\r\n$NestedObjects =\r\n [pscustomobject]@{a=1; b=[pscustomobject]@{c=2}},\r\n [pscustomobject]@{a=3; b=[pscustomobject]@{c=4}}\r\n\r\n$NestedObjects | Out-Host\r\n$NestedObjects | Select-Object a -ExpandProperty b | Out-Host\r\n\r\n$NestedObjects | Out-Host\r\n$NestedObjects | Select-Object a -ExpandProperty b | Out-Host\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\n\r\nRe-running the same `Select-Object` statement should produce the same output, and should not modify its input objects, so the example code should produce the following output:\r\n\r\n```none\r\na b\r\n- -\r\n1 @{c=2}\r\n3 @{c=4}\r\n\r\n\r\n\r\nc a\r\n- -\r\n2 1\r\n4 3\r\n\r\n\r\na b\r\n- -\r\n1 @{c=2}\r\n3 @{c=4}\r\n\r\n\r\n\r\nc a\r\n- -\r\n2 1\r\n4 3\r\n\r\n\r\n```\r\n\r\nActual behavior\r\n---------------\r\n\r\nInstead of creating new objects with the appropriate fields, `Select-Object` modifies the objects specified by `-ExpandProperty`, which causes an error the second time the same code runs:\r\n\r\n```none\r\na b\r\n- -\r\n1 @{c=2}\r\n3 @{c=4}\r\n\r\n\r\n\r\nc a\r\n- -\r\n2 1\r\n4 3\r\n\r\n\r\n\r\na b\r\n- -\r\n1 @{c=2; a=1}\r\n3 @{c=4; a=3}\r\n\r\n\r\nSelect-Object : The property cannot be processed because the property \"a\" already exists.\r\nAt line:9 char:18\r\n+ $NestedObjects | Select-Object a -ExpandProperty b | Out-Host\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n+ CategoryInfo : InvalidOperation: (@{a=1; b=}:PSObject) [Select-Object], PSArgumentException\r\n+ FullyQualifiedErrorId : AlreadyExistingUserSpecifiedPropertyExpand,Microsoft.PowerShell.Commands.SelectObjectCommand\r\n\r\n\r\nSelect-Object : The property cannot be processed because the property \"a\" already exists.\r\nAt line:9 char:18\r\n+ $NestedObjects | Select-Object a -ExpandProperty b | Out-Host\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n+ CategoryInfo : InvalidOperation: (@{a=3; b=}:PSObject) [Select-Object], PSArgumentException\r\n+ FullyQualifiedErrorId : AlreadyExistingUserSpecifiedPropertyExpand,Microsoft.PowerShell.Commands.SelectObjectCommand\r\n\r\nc a\r\n- -\r\n2 1\r\n4 3\r\n```\r\n\r\nEnvironment data\r\n----------------\r\n\r\n\u003c!-- provide the output of $PSVersionTable -->\r\n\r\n```powershell\r\n> $PSVersionTable\r\n\r\nName Value\r\n---- -----\r\nPSVersion 6.0.1\r\nPSEdition Core\r\nGitCommitId v6.0.1\r\nOS Microsoft Windows 10.0.17134\r\nPlatform Win32NT\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n```\r\n","author":{"url":"https://github.com/bstrautin","@type":"Person","name":"bstrautin"},"datePublished":"2018-09-12T18:26:40Z","url":"https://github.com/PowerShell/PowerShell/issues/7768"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:071155cb-61d2-11b4-1115-4de59750c520 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C6BC:9FF1A:2893551:38A1AA4:6AFD51C9 |
| html-safe-nonce | 781cd45c5f9863fd730267f5572e9967f652122226fb19901d36ec7368be50e6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNkJDOjlGRjFBOjI4OTM1NTE6MzhBMUFBNDo2QUZENTFDOSIsInZpc2l0b3JfaWQiOiI2NjYyNTk1ODY3MjU3OTQyNDkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 46476d66312ce143322a08eb4e6b625233b49bc01a1d9c9ca0cf8b15944d7878 |
| hovercard-subject-tag | issue:359599363 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/7768/issue_layout |
| twitter:image | https://opengraph.githubassets.com/92fc9113ce278383f004b179236111c0f9b5901f06ac6af55578900967c3453d/PowerShell/PowerShell/issues/7768 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/92fc9113ce278383f004b179236111c0f9b5901f06ac6af55578900967c3453d/PowerShell/PowerShell/issues/7768 |
| og:image:alt | Select-Object should never modify its input objects, but it does, when using both the -ExpandProperty and -Property parameters. This behavior is documented, but wrong. Steps to reproduce $NestedObj... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bstrautin |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width