How to Control Column Widths With Format-Table in PowerShell
The long outputs are often harder to display in table format on the PowerShell console. While displaying the tabular output in PowerShell, you might have noticed that the output lines are truncated.
This is because the column data does not fit the column width or is too long to display on the console. This tutorial will teach you to control column widths with Format-Table
in PowerShell.
Use AutoSize
Parameter to Control Column Widths With Format-Table
in PowerShell
The Format-Table
cmdlet format the output as a table in PowerShell. By default, the data in columns truncate if it exceeds the column width.
The following command displays the recent five entries in the System event log in a tabular format.
Command:
Get-EventLog -LogName System -Newest 5
Output:
As you see in the output, some entries in the fourth and the sixth columns are truncated, making it difficult to read the data. You can pipe the Format-Table -AutoSize
command to adjust the columns’ width to reduce truncation.
Command:
Get-EventLog -LogName System -Newest 5 | Format-Table -AutoSize
Output:
Here the entries in the fourth column are visible, but the entries in the sixth column are still truncated. You can use the -Wrap
parameter that displays the text exceeding column width on the next line.
Command:
Get-EventLog -LogName System -Newest 5 | Format-Table -AutoSize -Wrap
Output: