7.4. Using the format-table Cmdlet

The format-table cmdlet allows you to display information from a pipeline in a table. In some situations, the visual appearance produced by the format-table cmdlet is the same as that produced by the default formatter. If you use the format-table cmdlet with no properties specified for display the display is the same as the default output. You can confirm this by comparing:

get-process sql*

and:

get-process sql* |
format-table

As you can see in Figure 7-21, the displayed columns are the same.

Figure 7.21. Figure 7-21

The usefulness of format-table is that it allows you to take control of the visual output to produce an appearance that is more selective and/or better laid out than the display produced by the default for-matter. You do this by using parameters to modify the behavior of the format-table cmdlet.

The format-table cmdlet has several parameters, shown in the following list. Only the property parameter is a positional parameter.

  • property — Specifies a property or list of properties to be displayed. You cannot use th eproperty parameter if you use the view parameter in the same command.

  • AutoSize — Specifies that the width of a column is to be adjusted automatically according to the width of the data.

  • HideTableHeaders — If present specifies that the column headers are to be omitted.

  • GroupBy — Specifies that output is to be grouped based ...

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.