Search notes:

PowerShell cmdLet Out-Default

The cmdLet out-default is automatically added to every pipeline's end.
out-default tries to render the objects it receives according to their format definitions in a text-representation on the console.

If objects are strings

If these objects are strings, it simply passes these these strings to out-host.

If there is a registered view for the objects' type

If the objects are not strings, out-default checks if there is a registered view for the received objects' types.
Such views define a formatter for the respective object type. There are four of them and each of them corresponds to a cmdLet whose verb is format:

There is no registered view

If out-default does not find a registered view, out-default uses the first object it receives to determine the number of properties it has.
If this number is greater or equal to 5, it pipes the objects to format-list, otherwise to format-table.

Overriding out-default

out-default can be overridden.
function out-default {

   param (
      [parameter (valueFromPipeline=$true)] $val
   )

   begin  { write-host "overwridden out-default is called" }
   process{ write-host "  received: $val"                  }

}
Github repository about-PowerShell, path: /cmdlets/default/out/overriding/out-default.ps1
A simple pipeline:
'foo', 'bar', 'baz'
Github repository about-PowerShell, path: /cmdlets/default/out/overriding/pipeline.ps1
Executing this pipeline prints
overwridden out-default is called
  received: foo
  received: bar
  received: baz
Remove the overriding out-default:
remove-item function:out-default
Github repository about-PowerShell, path: /cmdlets/default/out/overriding/rm-out-default.ps1
Unfortunately, I didn't figure out how I can override out-default in a PowerShell script file.

Links

Some of the information on this page is condensed from the valuable post by Jeffrey Snover: How PowerShell Formatting and Outputting REALLY works

See also

Powershell command noun: default
PowerShell command verb: out

Index