liveBook · Manning

Format-Table

As explained in Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS

Format-Table is a PowerShell cmdlet that displays objects in a tabular format using selected properties or calculated expressions.

Format-Table (ft) displays PowerShell objects as tables. Choose properties, use wildcards, rename columns, group sorted results, or wrap truncated values. section 11.3

Useful formatting patterns include:

  • Select columns with `Format-Table Name,ID,Responding`; use `-Property *` or wildcard patterns to request broader sets of properties. section 11.11 section 11.3
  • Add `-Wrap` when long values are truncated, preserving information by making the table taller. section 11.3
  • Use `-GroupBy` after sorting on the same property to create grouped sections, such as running and deallocated Azure virtual machines. section 11.3

Create a readable calculated column

Convert process virtual memory from bytes to whole megabytes with `Get-Process | Format-Table Name,@{name='VM(MB)';expression={$_.VM / 1MB -as [int]}}`. A hash-table expression supplies the column name and calculation. section 11.6

Put Format-Table at the end of a pipeline, or immediately before Out-File. It emits formatting instructions rather than the original objects, so later object-processing cmdlets receive the wrong input. section 11.9.1

How Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS covers it

How deep it goes
Explains properties, wrapping, grouping, calculated columns, and pipeline placement through runnable commands.
Examples
Demonstrates process tables, custom memory columns, command listings, and grouped Azure virtual machines.
What it assumes
Assumes basic PowerShell pipelines, object properties, and hash-table expressions for calculated columns.
What you can do after
Apply it via PowerShell commands to produce readable tables without losing values to truncation.
How it connects
Connects Format-Table with PowerShell pipelines, calculated properties, Format-List, Select-Object, Out-File, and Out-GridView.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS. The section links point to the parts of the book it draws on.