Format-Table

 

SYNOPSIS

Formats the output as a table.

 

SYNTAX

Format-Table [[-property] <Object[]>] [-autosize] [-hideTableHeaders] [-groupBy <Object>] [-wrap] [-view <string>] [-force] [-inputObject <psobject>] [-expand <string>] [-displayError] [-showError] [<CommonParameters>]

 

DETAILED DESCRIPTION

The Format-Table cmdlet formats the output of a command as a table with a selected properties of the object in each column. The object type determines the default layout and properties that are displayed in each column, but you can use the Property parameter to select the properties that you want to see.

 

You can also use Format-Table to add calculated properties to an object before displaying it. To do so, you 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.

 

PARAMETERS

 

-property <Object[]>

Specifies the object properties that appear in the display and the order in which they appear. Wildcards are permitted. 

 

If you omit this parameter, the properties that appear in the display depend on the object being displayed. The parameter name ("-Property") is optional. You cannot use the Property and View parameters in the same command.

 

Required?

false

Position?

1

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-autosize <SwitchParameter>

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.

 

Required?

false

Position?

named

Default value

False

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-hideTableHeaders <SwitchParameter>

Omits the column headings from the table.

 

Required?

false

Position?

named

Default value

False

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-groupBy <Object>

Formats the output in groups based on a shared property or value. Enter an expression or a property of the output.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-wrap <SwitchParameter>

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

 

Required?

false

Position?

named

Default value

False

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-view <string>

Specifies the name of an alternate table format or "view." You cannot use the Property and View parameters in the same command.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-force <SwitchParameter>

Overrides restrictions that prevent the command from succeeding, just so the changes do not compromise security. For example, Force will override the read-only attribute or create directories to complete a file path, but it will not attempt to change file permissions.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-inputObject <psobject>

Specifies the objects to be formatted. Enter a variable that contains the objects or type a command or expression that gets the objects.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

true (ByValue)

Accept wildcard characters? 

false

 

-expand <string>

Formats the collection object, as well as the objects in the collection. This parameter is designed to format objects that support the ICollection (System.Collections) interface.

 

Valid values are:

 

·          Enum (default): Displays the properties of the objects in the collection.

·          Core: Displays the properties of the collection object.

·          Both: Displays the properties of the collection object and the properties of objects in the collection.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-displayError <SwitchParameter>

Displays errors at the command line.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-showError <SwitchParameter>

Sends errors through the pipeline.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. For more information, type, "get-help about_commonparameters".

 

INPUT TYPE

Object

 

RETURN TYPE

Formatted objects

 

NOTES

 

For more information, type "Get-Help Format-Table -detailed". For technical information, type "Get-Help Format-Table -full".

 

When specifying multiple values for a parameter, use commas to separate the values. For example, "<parameter-name> <value1>, <value2>".

 

You can also refer to Format-Table by its built-in alias, "FT". For more information, see About_Alias.

 

The -Groupby parameter assumes that the objects are sorted. Before using Format-Customto group the objects, use Sort-Objectto sort them.

 

The View parameter lets you specify an alternate format for the table. You can use the views defined in the *.format.PS1XML files in the Windows PowerShell directory or you can create your own views in new PS1XML files and use the Update-FormatData cmdlet to include them in Windows PowerShell.

 

The alternate view for the View parameter must use table format; if not, the command fails. If the alternate view is a list, use Format-List. If the alternate view is neither list nor table, use Format-Custom.

 

You can use Format-Table to add a calculated property to an object. You can also add a calculated property by using Add-Memberor Select-Object. For details, see the help for these cmdlets.

 

EXAMPLE 1

 

get-pssnapin | format-table -auto

 

This command formats information about Windows PowerShell snap-ins in a table. By default, they are formatted in a list. The Get-PsSnapincmdlets gets objects representing the snap-ins. The pipeline operator (|) passes the object to the Format-Table command. Format-Table formats the objects in a table. The Autosize parameter adjusts the column widths to minimize truncation.

 

EXAMPLE 2

 

get-process | format-table -groupby basepriority -wrap

 

This command displays the processes on the computer in groups with the same base priority class. The Get-Processcmdlets gets objects representing each process on the computer. The pipeline operator (|) passes the object to the Format-Table command. The Groupby parameter arranges the data about the processes into groups based on the value of their basepriority property. The Wrap parameter assures that data is displayed on the next line, instead of being truncated.

 

EXAMPLE 3

 

get-process | sort-object starttime | format-table -view starttime

 

This command displays information about the processes on the computer in group based on the start date of the process. It uses the Get-Process cmdlet to get objects representing the processes on the computer. The pipeline operator (|) sends the output of Get-Process to the Sort-Object cmdlet, which sorts it based on the StartTime property. Another pipeline operator sends the sorted results to Format-Table.

 

The View parameter is used to select the StartTime view that is defined in the DotNetTypes.format.ps1xml for System.Diagnostics.Process objects, like those returned by Get-Process. This view converts the StartTime of the process to a short date and then groups the processes by start date.

 

The DotNetTypes.format.ps1xml also contains a Priority view for processes and you can create your own format.ps1xml files with customized views.

 

EXAMPLE 4

 

get-service | format-table -property Name, DependentServices

 

This command displays all of the services on the computer in a table with two columns, "Name" and "DependentServices". The command uses the Get-Servicecmdlet to get all of the services on the computer. The pipeline operator (|) sends the results to the Format-Table cmdlet, which formats the output in a table. The Property parameter specifies the properties that appear in the table as columns. The name of the Property parameter is optional, so you can omit it ("format-table Name, DependentServices").

 

Property and DependentServices are just two of the properties of service objects. To see all of the properties, type "get-service | get-member".

 

EXAMPLE 5

 

get-process notepad | format-table ProcessName, @Label="TotalRunningTime"; Expression={(get-date) - $_.StartTime}}

 

This command shows how to use a calculated property in a table. The command displays a table with the process name and total running time of all Notepad processes on the local computer. The total running time is calculated by subtracting the start time of each process from the current time.

 

The command uses the Get-Process cmdlet to get all processes named "Notepad" on the local computer. The pipeline operator (|) sends the results to Format-Table, which displays a table with two columns: ProcessName, a standard property of processes, and "TotalRunningTime," a calculated property.

 

The TotalRunningTime property is specified by a hash table with two keys, "Label" and "Expression". The name of the property is assigned to the "Label" key. The calculation is assigned to the "Expression" key. The expression gets the StartTime property of each process object and subtracts it from the result of a Get-Date command, which gets the current date (and time).

 

EXAMPLE 6

 

$processes = get-wmiobject -ComputerName Server01 `

win32_process -filter "name='notepad.exe'"

$processes | format-table ProcessName, @{ Label = "Total  Running Time"; `

Expression={(get-date) - $_.ConvertToDateTime($_.CreationDate)}}

 

This command is similar to the previous command, except that it uses the Get-WmiObjectcmdlet and the Win32_Processes class to display information about Notepad processes on a remote computer.

 

This command uses the Get-WmiObject cmdlet to retrieve instances of the Win32_Process WMI class that describes all of the processes on the Server01 computer that are named Notepad.exe. The command stores the process information in the $processes variable. The pipeline operator (|) sends the process information in the $processes variable to the Format-Table cmdlet which displays the ProcessName of each process along with a new calculated property.

 

The name of the new calculated property,"Total Running Time," is assigned to the "Label" key. The script block that is assigned to the Expression key calculates how long the process has been running by subtracting the creation date of the process from the current date. The Get-Date cmdlet gets the current date. The ConvertToDateTime method converts the CreationDate property of the Win32_process object from a WMI CIM_DATETIME object to a .NET DateTime object that can be compared with the output of Get-Date. Then, the converted creation date is subtracted from the current date. The result is the value of "Total Running Time."

 

The backtick symbols (`) are line continuation characters.

 

RELATED LINKS

Format-Custom

Format-List

Format-Wide

Out-Host

Out-File