PowerShell Format-Table Tutorial

PowerShell is a very featureful command line interface that provides the Fromat-Table command which can be simply used to format tables which are generally the output of the executed commands. The Format-Table command can be used to select specific properties, group tables, hide headers, etc. In this tutorial, we examine different features of the Format-Table.

Auto Size Table

By default, all table content is put into the standard output. The -AutoSize option can be used to fit the table content by trimming the columns.

PS> Get-Process | Format-Table -AutoSize

Group By Table

The Format-Table command can be also used to group output according to the specified column values. This can be useful to list the same values on the same screen. In the following example, we use the Get-Process command and group output by the ProcessName . The -GroupBy attribute is used to group ouıtput.

PS> Get-Process | Format-Table -GroupBy ProcessName

Display Only Specified Columns (Hide Columns)

Another useful feature of the Format-Table command is the ability to display only specified columns. The -Propery attribute is used to provide column names. Single or multiple columns can be specified by separating them from commas. In the following example, we only display columns named CPU, Id and ProcessName.

PS> Get-Process | Format-Table -Property CPU,Id,ProcessName
Display Only Specified Columns (Hide Columns)

Debug Format Table

During the formatting of the table, we may get some errors that are not displayed by default. The -DisplayError or -ShowError can be used to display errors if they exist.

Get-Process | Format-Table -Property CPU,Id,ProcessName -DisplayError

Hide Table Headers

By default, every time the Format-Table is executed the table headers are displayed. If we want to get the raw table without the table headers the -HideTableHeaders option.

PS> Get-Process | Format-Table -HideTableHeaders
Hide Table Headers

RepeatHeader

In some cases, the output may a more than a page where the headers stay on the first page. We can show headers on every page by repeating the header. The -RepeatHeader can be used to repeat headers on every page of the table output.

PS> Get-Process | Format-Table -RepeatHeader

Do Not Truncate (Wrap) Line

If some table data exceeds the line it is truncated and not displayed. We can prevent this and wrap the line with the -Wrap option like below.

PS> Get-Process | Format-Table -Wrap
See also  How To Open Microsoft Edge In Windows?

Leave a Comment