CmdID / PowerShell / Cmdlets / Format
Format-Table
Formats the output as a table. PowerShell reference
From the PowerShell reference
12 parameters
Alias ft
What it does
Formats the output as a table. The Format-Table cmdlet formats the output of a command as a table with the selected properties of the object in each column. The object type determines the default layout and properties that are displayed in each column. You can use the Property parameter to select the properties that you want to display. PowerShell uses default formatters to define how object types are displayed. You can use .ps1xml files to create custom views that display an output table with specified properties. After a custom view is created, use the View parameter to display the table with your custom view. For more information about views, see about_Format.ps1xml. You can use a hash table to add calculated properties to an object before displaying it and to specify the column headings in the table. To add a calculated property, use the Property or GroupBy parameter. For more information about hash tables, see about_Hash_Tables.
Format-Table [[-Property] <Object[]>] [-AutoSize] [-RepeatHeader] [-HideTableHeaders] [-Wrap] [-GroupBy <Object>] [-View <string>] [-ShowError] [-DisplayError] [-Force] [-Expand <string>] [-InputObject <psobject>] [<CommonParameters>]
Format PowerShell host
Get-Host | Format-Table -AutoSizeIdentifyFormat processes by BasePriority
Get-Process | Sort-Object -Property BasePriority |
Format-Table -GroupBy BasePriority -WrapIdentifyFormat processes by start date
Get-Process | Sort-Object StartTime | Format-Table -View StartTimeIdentifyUse a custom view for table output
Get-ChildItem -Path C:\Test | Format-Table -View MyGciViewIdentifyUse properties for table output
Get-Service | Format-Table -Property Name, DependentServicesIdentifyFormat a process and calculate its running time
Get-Process notepad |
Format-Table ProcessName, @{
Label = "TotalRunningTime"
Expression = {(Get-Date) - $_.StartTime}
}IdentifyFormat Notepad processes
$Processes = Get-CimInstance -Class Win32_Process -Filter "name='notepad.exe'"
$Processes | Format-Table ProcessName, @{
Label = "Total Running Time"
Expression = {(Get-Date) - $_.CreationDate}
}IdentifyTroubleshooting format errors
Get-Date | Format-Table DayOfWeek, { $_ / $null } -DisplayErrorIdentifyIts page in the reference: Format-Table.
Parameters
-AutoSizeIndicates that the cmdlet adjusts the column size and number of columns based on the width of the data. By default, the column size and number are determined by the view.-DisplayErrorIndicates that the cmdlet displays errors on the command line. This parameter can be used as a debugging aid when you're formatting expressions in a Format-Table command and need to troubleshoot the expressions.-ExpandSpecifies the format of the collection object and the objects in the collection. This parameter is designed to format objects that support the ICollection(System.Collections) interface. The default value is EnumOnly. The acceptable values for this parameter are as follows:
- EnumOnly: Displays the properties of the objects in the collection.
- CoreOnly: Displays the properties of the collection object.
- Both: Displays the properties of the collection object and the properties of objects in the
collection.-ForceIndicates that the cmdlet directs the cmdlet to display all the error information. Use with the DisplayError or ShowError parameter. By default, when an error object is written to the error or display streams, only some error information is displayed.
Also required when formatting certain .NET types. For more information, see the Notes section.-GroupBySpecifies sorted output in separate tables based on a property value. For example, you can use GroupBy to list services in separate tables based on their status.
Enter an expression or a property. The GroupBy parameter expects that the objects are sorted. Use the Sort-Object cmdlet before using Format-Table to group the objects.
The value of the GroupBy parameter can be a new calculated property. The calculated property can be a scriptblock or a hashtable. Valid key-value pairs are:
- Name (or Label) - <string>
- Expression - <string> or <scriptblock>
- FormatString - <string>
For more information, see about_Calculated_Properties.-HideTableHeadersOmits the column headings from the table.-InputObjectSpecifies the objects to format. Enter a variable that contains the objects, or type a command or expression that gets the objects.-PropertySpecifies the object properties that appear in the display and the order in which they appear. Type one or more property names, separated by commas, or use a hash table to display a calculated property. Wildcards are permitted.
If you omit this parameter, the properties that appear in the display depend on the first object's properties. For example, if the first object has PropertyA and PropertyB but subsequent objects have PropertyA, PropertyB, and PropertyC, then only the PropertyA and PropertyB headers are displayed.
The Property parameter is optional. You can't use the Property and View parameters in the same command.
The value of the Property parameter can be a new calculated property. The calculated property can be a scriptblock or a hash table. Valid key-value pairs are:
- Name (or Label) <string>
- Expression - <string> or <scriptblock>
- FormatString - <string>
- Width - <int32> - must be greater than 0
- Alignment - value can be Left, Center, or Right
For more information, see about_Calculated_Properties.-RepeatHeaderRepeats 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.-ShowErrorThis parameter sends errors through the pipeline. This parameter can be used as a debugging aid when you're formatting expressions in a Format-Table command and need to troubleshoot the expressions.-ViewIn PowerShell 5.1 and earlier versions, the default views are defined in *.format.ps1xml files stored in $PSHOME.
The View parameter lets you specify an alternate format or custom view for the table. You can use the default PowerShell views or create custom views. For more information about how to create a custom view, see about_Format.ps1xml.
The alternate and custom views for the View parameter must use the table format, otherwise,
Format-Table fails. If the alternate view is a list, use the Format-List cmdlet. If the
alternate view isn't a list or a table, use the Format-Custom cmdlet.
You can't use the Property and View parameters in the same command.-WrapDisplays text that exceeds the column width on the next line. By default, text that exceeds the column width is truncated.