How to Use Format-List in PowerShell: Syntax and Examples
Use the
Format-List cmdlet in PowerShell to display object properties in a vertical list format. It is useful when you want to see all or selected properties clearly instead of a table. Simply pipe an object to Format-List and optionally specify property names.Syntax
The basic syntax of Format-List is:
Format-List [-Property] <string[]>- Specifies which properties to display.Format-List [-InputObject] <psobject>- Accepts the object to format, usually via pipeline.Format-List [-Force]- Shows hidden or normally hidden properties.
You usually use it by piping objects to it, like Get-Process | Format-List.
powershell
Get-Process | Format-List [-Property <property1>, <property2>, ...] [-Force]
Example
This example shows how to list all properties of the current PowerShell process in a readable list format. It demonstrates using Format-List without specifying properties to see everything.
powershell
Get-Process -Id $PID | Format-List
Output
Name : powershell
Id : 1234
Handles : 100
CPU : 0.03
StartTime : 6/1/2024 10:00:00 AM
... (other properties listed vertically)
Common Pitfalls
One common mistake is using Format-List too early in a pipeline, which converts objects to formatting data and breaks further processing. Always use Format-List as the last command in the pipeline.
Another pitfall is not specifying properties when you want only a few, causing cluttered output.
powershell
Get-Process | Format-List | Where-Object { $_.CPU -gt 1 }
# This will not work as expected because Format-List outputs formatting data, not objects.
# Correct way:
Get-Process | Where-Object { $_.CPU -gt 1 } | Format-ListQuick Reference
| Parameter | Description |
|---|---|
| -Property | Specify which properties to display in the list. |
| -Force | Show hidden or normally unavailable properties. |
| -InputObject | Specify the object to format (usually via pipeline). |
| (No parameters) | Displays all properties of the input object. |
Key Takeaways
Use Format-List to display object properties vertically for better readability.
Always place Format-List at the end of the pipeline to avoid breaking object flow.
Specify properties with -Property to limit output to what you need.
Use -Force to see hidden properties if necessary.
Format-List is ideal for detailed inspection of objects in PowerShell.