Formatting Output

<Pipeline> | <Formatting Command>

When objects reach the end of the output pipeline, PowerShell converts them to text to make them suitable for human consumption. PowerShell supports several options to help you control this formatting process:

PowerShell formatting commands

Formatting Command

Result

Format-Table <Property List>

Formats the properties of the input objects as a table, including only the object properties you specify. If you do not specify a property list, PowerShell picks a default set.

In addition to supplying object properties, you may also provide advanced formatting statements:

PS > Get-Process | `
   Format-Table -Auto Name,`
   @{Label="HexId";
     Expression={ "{0:x}" -f $_.Id}
     Width=4
     Align="Right"

}

The advanced formatting statement is a hashtable with the keys, Label and Expression (or any short form of them.) The value of the expression key should be a script block that returns a result for the current object (represented by the $_ variable.)

For more information about the Format-Table cmdlet, type Get-Help Format-Table

Format-List <Property List>

Formats the properties of the input objects as a list, including only the object properties you specify. If you do not specify a property list, PowerShell picks a default set.

The Format-List cmdlet supports the advanced formatting statements as used by the Format-Table cmdlet.

The Format-List cmdlet is the one you will use most often to get a detailed summary of an object’s properties.

The command, Format-List ...

Get Windows PowerShell Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.