Title: `OutOfBand` custom format definitions require `-Force` when using `Format-*` cmdlets · Issue #10408 · PowerShell/PowerShell · GitHub
Open Graph Title: `OutOfBand` custom format definitions require `-Force` when using `Format-*` cmdlets · Issue #10408 · PowerShell/PowerShell
X Title: `OutOfBand` custom format definitions require `-Force` when using `Format-*` cmdlets · Issue #10408 · PowerShell/PowerShell
Description: This is related to a longstanding issue with PowerShell that recently was brought up in a discussion on PowerShell/PowerShell-RFC#215. Consider the following 10 object types: System.Management.Automation.DebugRecord System.Management.Aut...
Open Graph Description: This is related to a longstanding issue with PowerShell that recently was brought up in a discussion on PowerShell/PowerShell-RFC#215. Consider the following 10 object types: System.Management.Auto...
X Description: This is related to a longstanding issue with PowerShell that recently was brought up in a discussion on PowerShell/PowerShell-RFC#215. Consider the following 10 object types: System.Management.Auto...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/10408
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`OutOfBand` custom format definitions require `-Force` when using `Format-*` cmdlets","articleBody":"This is related to a longstanding issue with PowerShell that recently was brought up in a discussion on [PowerShell/PowerShell-RFC#215](https://github.com/PowerShell/PowerShell-RFC/pull/215).\r\n\r\nConsider the following 10 object types:\r\n\r\n`System.Management.Automation.DebugRecord`\r\n`System.Management.Automation.InformationRecord`\r\n`System.Management.Automation.VerboseRecord`\r\n`System.Management.Automation.WarningRecord`\r\n`Deserialized.System.Management.Automation.DebugRecord`\r\n`Deserialized.System.Management.Automation.VerboseRecord`\r\n`Deserialized.System.Management.Automation.WarningRecord`\r\n`System.Exception`\r\n`System.Management.Automation.ErrorRecord`\r\n`System.Management.Automation.ScriptBlock`\r\n\r\nWhen you are working with any of those types as _captured data_ (i.e. not as data that is streamed something other than standard output, but as something that you captured in a variable and are outputting in your terminal), if you pipe an instance of any of those types to `Format-Table`, `Format-List`, `Format-Wide`, or `Format-Custom`, you will still be presented with their default (custom) format unless you use the `-Force` parameter that is common to the `Format-*` cmdlets.\r\n\r\nThis behaviour, which has been in PowerShell since version 1, is unexpected. If you pipe data to a specific `Format-*` cmdlet, you expect that data to be shown in that format without having to `-Force` it.\r\n\r\nThe problem with `OutOfBand` is that the way PowerShell is programmed today, the `-Force` parameter is required to override the `OutOfBand` default output for a given type. That behaviour is the crux of this issue.\r\n\r\nI'm currently investigating what can be done, if anything, to allow these types to use the requested format without requiring `-Force`.\r\n\r\n# Steps to reproduce\r\n\r\n```powershell\r\nfunction Test-FormatScriptBlock {\r\n [CmdletBinding()]\r\n param()\r\n Write-Verbose -Verbose -Message 'This function outputs a bunch of OutOfBand types.'\r\n {Write-Output 'This is a script block'}\r\n Write-Warning 'This might not function quite the way you think'\r\n Get-Process -Id 1234321231\r\n Write-Debug -Debug -Message 'Debugging is fun!'\r\n {'This is another script block'}\r\n}\r\n\r\nfunction Test-FormatError {\r\n [CmdletBinding()]\r\n param()\r\n Get-Item -LiteralPath DoesNotExist -ErrorVariable myError -ErrorAction SilentlyContinue\r\n Write-Information -MessageData 'This outputs an error.' -InformationAction Continue\r\n $myError\r\n Write-Information -MessageData 'All done.' -InformationAction Continue\r\n}\r\n\r\nTest-FormatScriptBlock | Format-List *\r\nTest-FormatError | Format-List *\r\n```\r\n\r\n# Expected behavior\r\n\r\n```none\r\nVERBOSE: This function outputs a bunch of OutOfBand types.\r\n\r\nAttributes : {}\r\nFile :\r\nIsFilter : False\r\nIsConfiguration : False\r\nModule :\r\nStartPosition : System.Management.Automation.PSToken\r\nDebuggerHidden : False\r\nId : 012350e3-0d0f-4922-b9f2-eef17544e2a3\r\nAst : {Write-Output 'This is a script block'}\r\n\r\nWARNING: This might not function quite the way you think\r\nGet-Process : Cannot find a process with the process identifier 1234321231.\r\nAt line:7 char:5\r\n+ Get-Process -Id 1234321231\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n+ CategoryInfo : ObjectNotFound: (1234321231:Int32) [Get-Process], ProcessCommandException\r\n+ FullyQualifiedErrorId : NoProcessFoundForGivenId,Microsoft.PowerShell.Commands.GetProcessCommand\r\n\r\nDEBUG: Debugging is fun!\r\nAttributes : {}\r\nFile :\r\nIsFilter : False\r\nIsConfiguration : False\r\nModule :\r\nStartPosition : System.Management.Automation.PSToken\r\nDebuggerHidden : False\r\nId : 3af7b1c9-ba29-4155-87cd-925f9108f53b\r\nAst : {'This is another script block'}\r\n\r\nThis outputs an error.\r\n\r\nPSMessageDetails :\r\nException : System.Management.Automation.ItemNotFoundException: Cannot find path 'DoesNotExist' because it does not exist.\r\n at System.Management.Automation.LocationGlobber.ResolveDriveQualifiedPath(String path, CmdletProviderContext context, Boolean allowNonexistingPaths, CmdletProvider& providerInstance) in\r\n C:\\Users\\poshoholic\\source\\repos\\PowerShell\\src\\System.Management.Automation\\namespaces\\LocationGlobber.cs:line 559\r\n at System.Management.Automation.LocationGlobber.GetGlobbedMonadPathsFromMonadPath(String path, Boolean allowNonexistingPaths, CmdletProviderContext context, CmdletProvider& providerInstance) in\r\n C:\\Users\\poshoholic\\source\\repos\\PowerShell\\src\\System.Management.Automation\\namespaces\\LocationGlobber.cs:line 218\r\n at System.Management.Automation.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(String path, Boolean allowNonexistingPaths, CmdletProviderContext context, ProviderInfo& provider, CmdletProvider&\r\n providerInstance) in C:\\Users\\poshoholic\\source\\repos\\PowerShell\\src\\System.Management.Automation\\namespaces\\LocationGlobber.cs:line 779\r\n at System.Management.Automation.SessionStateInternal.GetItem(String[] paths, CmdletProviderContext context) in\r\n C:\\Users\\poshoholic\\source\\repos\\PowerShell\\src\\System.Management.Automation\\engine\\SessionStateItem.cs:line 130\r\n at System.Management.Automation.ItemCmdletProviderIntrinsics.Get(String path, CmdletProviderContext context) in\r\n C:\\Users\\poshoholic\\source\\repos\\PowerShell\\src\\System.Management.Automation\\engine\\ItemCmdletProviderInterfaces.cs:line 202\r\n at Microsoft.PowerShell.Commands.GetItemCommand.ProcessRecord() in C:\\Users\\poshoholic\\source\\repos\\PowerShell\\src\\Microsoft.PowerShell.Commands.Management\\commands\\management\\Navigation.cs:line 1969\r\nTargetObject : DoesNotExist\r\nCategoryInfo : ObjectNotFound: (DoesNotExist:String) [Get-Item], ItemNotFoundException\r\nFullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand\r\nErrorDetails :\r\nInvocationInfo : System.Management.Automation.InvocationInfo\r\nScriptStackTrace : at Test-FormatError, \u003cNo file>: line 4\r\n at \u003cScriptBlock>, \u003cNo file>: line 1\r\nPipelineIterationInfo : {0, 1}\r\n\r\nAll done.\r\n```\r\n\r\n# Actual behavior\r\n\r\n```none\r\nVERBOSE: This function outputs a bunch of OutOfBand types.\r\nWrite-Output 'This is a script block'\r\nWARNING: This might not function quite the way you think\r\nGet-Process : Cannot find a process with the process identifier 1234321231.\r\nAt line:7 char:5\r\n+ Get-Process -Id 1234321231\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n+ CategoryInfo : ObjectNotFound: (1234321231:Int32) [Get-Process], ProcessCommandException\r\n+ FullyQualifiedErrorId : NoProcessFoundForGivenId,Microsoft.PowerShell.Commands.GetProcessCommand\r\n\r\nDEBUG: Debugging is fun!\r\n'This is another script block'\r\n\r\nThis outputs an error.\r\nGet-Item : Cannot find path 'DoesNotExist' because it does not exist.\r\nAt line:4 char:5\r\n+ Get-Item -LiteralPath DoesNotExist -ErrorVariable myError -ErrorA ...\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n+ CategoryInfo : ObjectNotFound: (DoesNotExist:String) [Get-Item], ItemNotFoundException\r\n+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand\r\n\r\nAll done.\r\n```\r\n\r\n# Environment data\r\n\r\n```none\r\nName Value\r\n---- -----\r\nPSVersion 7.0.0-preview.2\r\nPSEdition Core\r\nGitCommitId 7.0.0-preview.2-70-g8234fbb04b437748b6782e9c45b0026c374ef12d\r\nOS Microsoft Windows 10.0.17763\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/KirkMunro","@type":"Person","name":"KirkMunro"},"datePublished":"2019-08-21T23:41:14Z","url":"https://github.com/PowerShell/PowerShell/issues/10408"}
| 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:6f87d611-33da-b490-85ee-e74591d62278 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D174:30AF58:2ABFAF0:3B7C6FD:6AFD563C |
| html-safe-nonce | 11188044438def1936f0eb32897ce4db8259fcb5727c1ac97258dcadae03891c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTc0OjMwQUY1ODoyQUJGQUYwOjNCN0M2RkQ6NkFGRDU2M0MiLCJ2aXNpdG9yX2lkIjoiNzk2NTg0MjM3MDcxMTA4MjU1NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 10e82faa30a54ca2dd5ebfefc7ad8bc4cc5bfccc57cd97123034c6e9ddb73c7c |
| hovercard-subject-tag | issue:483699806 |
| 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/10408/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d4fa7e9ae2dd0044a48ff58eda7c792984220b5c97057be98dd1a911c7fcc473/PowerShell/PowerShell/issues/10408 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d4fa7e9ae2dd0044a48ff58eda7c792984220b5c97057be98dd1a911c7fcc473/PowerShell/PowerShell/issues/10408 |
| og:image:alt | This is related to a longstanding issue with PowerShell that recently was brought up in a discussion on PowerShell/PowerShell-RFC#215. Consider the following 10 object types: System.Management.Auto... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | KirkMunro |
| 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