Format output as a table.

      Format-Table [-AutoSize] [[-property] Object[]] [-RepeatHeader] [-hideTableHeaders]
          [-groupBy Object] [-wrap] [-view string] [-force]
             [-inputObject psobject] [-expand string]
                [-displayError] [-showError] [CommonParameters]

       Adjust the column sizes based on the width of the data.
       Ignore any column details in the view.
       By default, the column size and number are determined by the view.

   -property Object[]
       The object properties to display (in order)
       Wildcards are permitted.
       You cannot use -Property and -View in the same command.

       Omit column headings from the table.

   -view string
       The name of an alternate format or "view." 
       The DotNetTypes.format.ps1xml formatting file defines these views.

   -groupBy Object
       Format the output in groups based on a shared property or value.
       Repeat displaying the header of a table after every screen full.
       The repeated header is useful when the output is piped to a pager such
       as 'less' or 'more' or paging with a screen reader.

       Display text that exceeds the column width on the next line. 
       By default, text that exceeds the column width is truncated.

       Directs the cmdlet to display all of the error information.
       Use with -DisplayError or -ShowError. 
By default, when an error object is written to the error or display streams, only some of the error information is displayed. -inputObject psobject The objects to format. A variable, command or expression that gets the objects. Use for flat collections, nested collections may need to be unwrapped and passed through the pipe. -expand string Where string is either "EnumOnly" (the default), "CoreOnly" or "Both" "CoreOnly" will format and display properties of the collection object itself, while "emumOnly" will enumerate and display the object properties. (designed around the ICollection (System.Collections) interface.) -displayError Display errors at the command line. -showError Send errors through the pipeline.

Standard Aliases for Format-Table: ft

The format- cmdlets emit specialized formatting directives, so they do not ouptut a standard PowerShell object, for this reason they should in the pipeline after (to the right) of any WHERE filter.

To output a table at full width, not restricted to the size of the console window, convert the table to a string and then pass to Write-Host:
... | Format-Table | Out-String | Write-Host

The value of -GroupBy or -Property can be a new calculated property. To create a calculated property, use a hash table. Valid keys are:

Name (or Label) string
Expression string or script block
FormatString string
Width int32    -Property only
Alignment      -Property only ("Left", "Center", or "Right")

In addition to formatting output as a table, Format-Table can be used to add calculated properties to an object before displaying it.

To add calculated properties, use the Property parameter to specify a hash table. The hash table must include two keys: Label and Expression. The Label key is assigned the name of the calculated property. The Expression key is assigned a script block that is evaluated to determine the value of the property.

Custom display formats can also be defined using XML tags see get-help about_Display.xml for details.


Print information about Windows PowerShell modules in a table:

PS C:\> get-module | format-table -wrap

Get a list of services, with the column sizes expanded to minimise truncation:

PS C:\> get-service | format-table -autosize

Print a list of running processes formatted into groups with the same base priority class:

PS C:\> get-process | format-table -groupby basepriority

Print the winlogon process, including a calculated total running time:

PS C:\> get-process winlogon | format-table ProcessName, @{Label="DD.HH:MM:Seconds"; Expression={(get-date) - $_.StartTime}}

Changing the above for the notepad process, notice that this this will add up the running time for ALL notepad processes currently running:

PS C:\> get-process notepad | format-table ProcessName, `
       @{Label="DD.HH:MM:Seconds"; Expression={(get-date) - $_.StartTime}}

“A lot of people are afraid to say what they want, thats why a lot of people don’t get what they want” ~ Madonna

Related PowerShell Cmdlets

format-custom - Format output using a customized view.
format-list - Format output as a list of properties, each on a new line.
format-wide - Format objects as a table of their properties.
out-file - Send command output to a file.
out-host - Send the pipelined output to the host.

Copyright © 1999-2024
Some rights reserved