7.3. Default Formatting

In pipelines that appear to have a single step, such as:

get-service

there is, in fact, an implicit final step in the pipeline, the default formatter. The visible step passes objects (in this case representing services) to a default formatter.

The default formatter for each cmdlet displays information that Microsoft perceives might be generally useful. Implicitly, the output is piped to the out-default cmdlet, which, in turn, pipes the output to the default formatter. The default formatter then displays output.

The file C:\WINDOWS\system32\windowspowershell\v1.0\powershellcore.format.ps1xml contains extensive information explaining how information about different types of objects is to be displayed (assuming that you installed Windows on drive C:). Figure 7-15 shows part of a copy of that file displayed in Internet Explorer. The elements refer to Microsoft.PowerShell.Commands.GroupInfo objects. Notice the presence of PropertyName elements, which are child elements of TableColumnItem elements. Three values are contained in those elements - Count, Name, and Group.

Figure 7.15. Figure 7-15

Execute the following command to demonstrate the default format from a pipeline using the group-object cmdlet as its last explicit step:

get-command |
group-object verb

Notice in Figure 7-16 that the default formatting for output from the group-object cmdlet produces Count, ...

Get Professional Windows® PowerShell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.