-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
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-Defaultis called even when the CLI (powershell.exe/pwsh) is called with the-NonInteractiveswitch. -
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-Defaultcall inside the CLI session; that is, the strings resulting from the CLI session'sOut-Defaultcall - 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.
- ID: ee6e614d-658d-32ac-dc39-e05e49e3da91
- Version Independent ID: aa4edc10-7fe1-7252-461a-998b6223f02e
- Content: Out-Default (Microsoft.PowerShell.Core)
- Content Source: reference/7/Microsoft.PowerShell.Core/Out-Default.md
- Product: powershell
- Technology: powershell-cmdlets
- GitHub Login: @SteveL-MSFT
- Microsoft Alias: slee