• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Think PowerShell

Think PowerShell

PowerShell for IT Pros

  • About
    • Who I Am
    • Why I Blog
    • Privacy Policy
  • Resources
    • More PowerShell Sites
    • Post Series Index
  • Get Help
  • Show Search
Hide Search

PowerShell formatting and output tricks

Aaron Rothstein · July 17, 2023 · Leave a Comment

Controlling and customizing output in PowerShell is an essential skill for any IT professional. Not only does it enhance readability, but it also allows for more effective data analysis and troubleshooting. In this article, we’ll explore how you can get the most out of your PowerShell output.

Understanding PowerShell’s default output

By default, PowerShell displays output as a list or table, depending on the amount and type of data. For instance, Get-Service shows output in a table with Status, Name, and DisplayName columns, while Get-Process includes more columns because process objects have more properties that are meaningful to most users.

Get-Service
Sample output from Get-Service cmdlet.
Get-Service sample output formatting.
Get-Process
Sample output from Get-Process cmdlet.
Get-Process sample output formatting.

PowerShell chooses the best format based on the data type and the current host’s capabilities. However, you can override this choice and format the output to meet your needs.

Controlling output with Format cmdlets

PowerShell includes several cmdlets for controlling output:

Format-Table

Displays the output in a table. You can specify which properties to show with the -Property parameter.

Get-Process | Format-Table -Property Name, CPU, Id
Get-Process piped to Format-Table.
Get-Process piped to Format-Table sample.

Format-List

Displays the output as a list, which is useful for objects with many properties.

Get-Service -Name wuauserv | Format-List -Property *
Example of formatted property list output.

Format-Wide

Displays the output as a wide table that only includes one property. It’s useful when you only need a quick glance at a single property for a set of objects.

Get-Process | Format-Wide -Property Name
Format-Wide example.
Format-Wide example.

Format-Custom

Provides a customized view of the output, giving you the most control.

Get-Service | Format-Custom -Property Name, Status
Format-Custom example.

Exporting output

In addition to controlling the display of output, PowerShell allows you to export output to various file formats for further analysis:

Export-Csv

Exports the output to a CSV file.

Get-Process | Export-Csv -Path processlist.csv

Out-File

Redirects the output to a text file.

Get-Service | Out-File -FilePath services.txt

ConvertTo-Json

Converts the output to JSON format, which is useful for web-related tasks.

Get-Process | ConvertTo-Json

Best practices

  • Use formatting cmdlets last: Always use the formatting cmdlets at the end of your pipeline. These cmdlets change the objects into formatting data, which can’t be used by other PowerShell cmdlets.
  • Be selective with properties: When using Format-Table or Format-List, select only the properties you need. Too much information can be as bad as too little.
  • Don’t overuse Format-Custom: While Format-Custom gives you the most control, it’s also the most complex and is usually overkill for most tasks. Stick with Format-Table, Format-List, and Format-Wide unless you have a good reason to use Format-Custom.

Conclusion

Mastering PowerShell output is crucial for efficient scripting and data analysis. By understanding the various formatting and exporting cmdlets, you can present your data in the most effective way for your needs.

More resources

  • Using Format commands to change output view | learn.microsoft.com

General

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Aaron

Think PowerShell

Copyright © 2025 · Monochrome Pro on Genesis Framework · WordPress · Log in