PowerShell: How to Use Format-Table with No Header


Often you may want to use the Format-Table cmdlet in PowerShell to display a table without the header row.

You can use the following methods to do so:

Method 1: Use Format-Table with No Header

Import-Csv $my_data | Format-Table -HideTableHeaders

This particular example displays the rows from a specific CSV file without the header row.

Note that a leading and trailing blank row will still be shown in the output, though.

Method 2: Use Format-Table with No Header and No Blank Lines

(Import-Csv $my_data | Format-Table -HideTableHeaders | Out-String).Trim()

This example displays the rows from a specific CSV file without a header row and without a leading or trailing blank row.

The following examples show how to use each method in practice.

Example 1: How to Use Format-Table with No Header in PowerShell

Suppose we have a CSV file located at the following path:

  • c:\users\bobbi\nba_data.csv

Suppose we use the following syntax to display the contents of this CSV file:

$my_data = "c:\users\bobbi\nba_data.csv"
Import-Csv $my_data | Format-Table

The following screenshot shows how to use this syntax in practice:

By default, the output is shown with a header row.

Suppose that we would like to instead show the output with no header row.

We can use the -HideTableHeaders parameter to do so:

$my_data = "c:\users\bobbi\nba_data.csv"
Import-Csv $my_data | Format-Table -HideTableHeaders

The following screenshot shows how to use this syntax in practice:

PowerShell Format-Table no header

We can see that the rows in the table are shown with no header.

Example 2: How to Use Format-Table with No Header and No Blank Lines in PowerShell

Suppose that we would like to show the output of the CSV file with no header row and no blank lines.

We can use the following syntax to do so:

$my_data = "c:\users\bobbi\nba_data.csv"
(Import-Csv $my_data | Format-Table -HideTableHeaders | Out-String).Trim()

The following screenshot shows how to use this syntax in practice:

PowerShell Format-Table no header and no blank lines

We can see that the table is now shown with no header and no leading or trailing blank.

By piping the output to Out-String and then by using the Trim() method we are able to remove all blank lines remove the output.

Note: You can find the complete documentation for the Format-Table cmdlet in PowerShell here.

Related Tutorials

The following tutorials explain how to perform other common tasks in PowerShell:

PowerShell: How to Sort a Table with Format-Table
PowerShell: How to Remove Elements from a Hash Table
PowerShell: How to Iterate Over a Hash Table

Leave a Reply