0
0
PowershellHow-ToBeginner · 3 min read

How to Use Format-Table in PowerShell: Syntax and Examples

Use Format-Table in PowerShell to display objects as formatted tables. You pipe objects to Format-Table and specify properties to show columns. It helps make output easier to read in a tabular form.
📐

Syntax

The basic syntax of Format-Table is:

  • Get-Command | Format-Table -Property Name, Version, Source
  • -Property specifies which object properties to show as columns.
  • -AutoSize adjusts column widths to fit content.
  • -Wrap wraps long text in columns.
  • -HideTableHeaders hides the column headers.
powershell
Format-Table [-Property <string[]>] [-AutoSize] [-Wrap] [-HideTableHeaders] [<CommonParameters>]
💻

Example

This example shows how to list running processes with selected properties in a table format. It uses Get-Process piped to Format-Table to display the process name, ID, and CPU time.

powershell
Get-Process | Format-Table -Property Name, Id, CPU -AutoSize
Output
Name Id CPU ---- -- --- System Idle Process 0 0 System 4 0 smss 388 0 csrss 464 0 wininit 528 0 ...
⚠️

Common Pitfalls

One common mistake is using Format-Table too early in a pipeline, which converts objects to formatting data and breaks further processing. Always use Format-Table as the last command in the pipeline.

Another pitfall is not using -AutoSize when columns have long text, causing truncated output.

powershell
Get-Process | Format-Table -Property Name | Where-Object { $_.Name -like "*svchost*" }

# This will fail because Format-Table outputs formatting data, not objects.

# Correct way:
Get-Process | Where-Object { $_.Name -like "*svchost*" } | Format-Table -Property Name, Id -AutoSize
📊

Quick Reference

ParameterDescription
-PropertySelects which properties to display as columns.
-AutoSizeAdjusts column widths to fit content, avoiding truncation.
-WrapWraps long text within columns instead of truncating.
-HideTableHeadersHides the column headers in the output.
-GroupByGroups output rows by a property value.

Key Takeaways

Use Format-Table at the end of a pipeline to format output as a table.
Specify properties with -Property to control which columns appear.
Use -AutoSize to prevent column truncation and improve readability.
Avoid using Format-Table before filtering or processing objects.
Use -Wrap to handle long text in table columns gracefully.