Skip to content

Out-Default: Linked "Out-Default: Secrets Revealed" article contains incorrect information #5132

@mklement0

Description

@mklement0

The blog posted linked to via "Out-Default: Secrets Revealed" in the "See also" section contains incorrect information:

  • Unlike what the blog post states, Out-Default is called even when the CLI (powershell.exe / pwsh) is called with the -NonInteractive switch.

  • The blog post also states:

if your code from the non-Interactive session returns an object to a console session it will call Out-Default in that console session. Even running PowerShell.exe with the -noninteractive seems to ultimately pass to Out-Default even though it's not done within the interactive session itself. I don't have a way to test this, but the fact that objects returned from a non-interactive session end up properly formatted serves as good evidence.

That is generally not true:

  • When the CLI is invoked with the command or script file specified as a string (as in the examples in the post; note that passing a command as a string is the only option when calling from outside of PowerShell), no objects are being returned, only strings, namely the lines of output resulting from the Out-Default call inside the CLI session; that is, the strings resulting from the CLI session's Out-Default call - the lines that make up the for-display formatting - are output as data to the caller's success output stream.

The situation is different if you call the CLI from within PowerShell and also use a script block { ... } for the command, in which case serialized XML representations are returned to the caller, which are indeed thendeserialized to objects (though often not type-faithfully) and then rendered via the caller's `Out-Default.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

Labels

area-coreArea - Microsoft.PowerShell.Core module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions