Title: -as operator does not recognize System.Management.Automation.PSCustomObject instances as such · Issue #4343 · PowerShell/PowerShell · GitHub
Open Graph Title: -as operator does not recognize System.Management.Automation.PSCustomObject instances as such · Issue #4343 · PowerShell/PowerShell
X Title: -as operator does not recognize System.Management.Automation.PSCustomObject instances as such · Issue #4343 · PowerShell/PowerShell
Description: Related: #5579 Steps to reproduce # Create a [System.Management.Automation.PSCustomObject] # Note that you cannot create a System.Management.Automation.PSCustomObject # instance with `New-Object System.Management.Automation.PSCustomObjec...
Open Graph Description: Related: #5579 Steps to reproduce # Create a [System.Management.Automation.PSCustomObject] # Note that you cannot create a System.Management.Automation.PSCustomObject # instance with `New-Object Sy...
X Description: Related: #5579 Steps to reproduce # Create a [System.Management.Automation.PSCustomObject] # Note that you cannot create a System.Management.Automation.PSCustomObject # instance with `New-Object Sy...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/4343
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"-as operator does not recognize System.Management.Automation.PSCustomObject instances as such","articleBody":"\u003csup\u003eRelated: #5579\u003c/sup\u003e\r\n\r\nSteps to reproduce\r\n------------------\r\n\r\n```powershell\r\n# Create a [System.Management.Automation.PSCustomObject]\r\n# Note that you cannot create a System.Management.Automation.PSCustomObject\r\n# instance with `New-Object System.Management.Automation.PSCustomObject ...`.\r\n# [pscustomobject] is actually [psobject] ([System.Management.Automation.PSObject])\r\n$co = [pscustomobject] @{ foo = 'bar' }\r\n\r\n$co.GetType().FullName\r\n\r\n'---'\r\n\r\n# This should be and is $True.\r\n# Note that using `-is [pscustomobject]` is NOT equivalent and while it also returns $True,\r\n# it does so for any object that has an (invisible) extra [psobject] wrapper, due to the identity\r\n# of [pscustomobject] and [psobject]. All objects returned from *cmdlets* have that extra\r\n# wrapper; e.g., `(Get-Item /) -is [pscustomobject]` yields $True also, while the seemingly\r\n# equivalent `[System.IO.DirectoryInfo]::new('/') -is [pscustomobject]` doesn't - see #5579\r\n$co -is [System.Management.Automation.PSCustomObject]\r\n\r\n'---'\r\n\r\n# The $co -as ... expression should effectively pass $co through, but doesn't.\r\n# Note that using `-as [pscustomobject]` is NOT equivalent - and pointless, because \r\n# it passes *any* object through, given that it is the same as `-as [psobject]`, which is what ALL \r\n# objects in PowerShell are (semi-secretly) wrapped in.\r\n$null -ne ($co -as [System.Management.Automation.PSCustomObject])\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\n\r\n```none\r\nSystem.Management.Automation.PSCustomObject\r\n---\r\nTrue\r\n---\r\nTrue\r\n```\r\n\r\nActual behavior\r\n---------------\r\n\r\n```none\r\nSystem.Management.Automation.PSCustomObject\r\n---\r\nTrue\r\n---\r\nFalse # !!\r\n```\r\n\r\nEnvironment data\r\n----------------\r\n\r\n```powershell\r\nPowerShell Core v6.0.0-beta.4 on macOS 10.12.5\r\nPowerShell Core v6.0.0-beta.4 on Ubuntu 16.04.2 LTS\r\nPowerShell Core v6.0.0-beta.4 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)\r\nWindows PowerShell v5.1.15063.413 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2017-07-25T19:02:49.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":24},"url":"https://github.com/4343/PowerShell/issues/4343"}
| 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:163bae82-6d4c-b0bd-f813-c75c4f89b9f4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 96BC:19C81F:138E890:1A18F4A:6A5AB73F |
| html-safe-nonce | d4f66920941c2bfff3966901d77194710429f9ba4d5ea8a1753757bcdc0b4510 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NkJDOjE5QzgxRjoxMzhFODkwOjFBMThGNEE6NkE1QUI3M0YiLCJ2aXNpdG9yX2lkIjoiNjkzOTE2MTAxNDQ2MzgwNTI0NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a5208e54ff59f6772127eabe814689cfb2002d74bb827f72945011f3cde760dd |
| hovercard-subject-tag | issue:245502690 |
| 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/4343/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9cba434d044231deae33e463dbb6952e83dd2f2b54337949e214cb031e3217c6/PowerShell/PowerShell/issues/4343 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9cba434d044231deae33e463dbb6952e83dd2f2b54337949e214cb031e3217c6/PowerShell/PowerShell/issues/4343 |
| og:image:alt | Related: #5579 Steps to reproduce # Create a [System.Management.Automation.PSCustomObject] # Note that you cannot create a System.Management.Automation.PSCustomObject # instance with `New-Object Sy... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2702febe50e53f9152dda552dc2049a5eb182778b2655abd5b8619e82e899b4a |
| 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 | c0211a077f9b056c5e115f996d9049616d85c3b5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width