How to remove the header from the output table in PowerShell and leave only the data
September 3, 2024
Most likely, you do not need to remove the table header
Before I tell you how to remove the header (column names) from the data output by a cmdlet and leave only the data itself, it is important to note that PowerShell is quite different from other programming languages in terms of output data.
While Python, Bash, PHP, and many other programming languages output and process text data line by line, PowerShell works with objects. If a cmdlet outputs a table, then most likely the cmdlet output an object that was processed by the Format-Table cmdlet for output to the screen – even if this is not explicitly shown anywhere. You can verify this by adding the line “ | Format-Table” to the cmdlet that outputs the table:
Get-ChildItem
The following command will give absolutely identical output:
Get-ChildItem | Format-Table
So, what does this mean from a practical point of view? In practical terms, if you pipe the output of a cmdlet to another cmdlet, it will receive an object (not the table you would see in standard output). This in turn means that the cmdlet that receives the object to process will correctly identify the meaningful data and will not be hampered by the table header.
So if you pipe data from cmdlet to cmdlet, you don't need to worry about removing table headers – PowerShell will correctly interpret and process the meaningful data without your help.
How to remove a table header in PowerShell
However, if you need to remove the table header (for example, to process the received rows in other command-line utilities, outside of PowerShell), then you need to do the following:
1) If you are outputting data using the Format-Table cmdlet, then add the “-hide” option to it
2) If you are outputting data without Format-Table, then add the line “ | Format-Table -hide”
For example, the original command:
Get-Location
To output only the data without the header:
Get-Location | Format-Table -hide
The -hide option is a shortcut for the -HideTableHeaders option, you can use the full option name if you prefer:
Get-Location | Format-Table -HideTableHeaders
Related articles:
- Hashtables in PowerShell (strings that start with @) (complete guide) (88.1%)
- Output encoding issues in PowerShell and third-party utilities running in PowerShell (SOLVED) (64.2%)
- mysqldump in PowerShell corrupts non-Latin characters when exporting database (SOLVED) (64.2%)
- Error “The '<' operator is reserved for future use.” (SOLVED) (64.2%)
- How to clear the terminal window in PowerShell. Analog of clear (64.2%)
- What is the difference between the LIKE operator and the equal sign (=) in MySQL/MariaDB. How to use LIKE in SQL (RANDOM - 50%)