PowerShell Logo Small

Format-Table



This is the built-in help made by Microsoft for the command 'Format-Table', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Formats the output as a table.

SYNTAX


Format-Table [[-Property] <Object[]>] [-AutoSize] [-DisplayError] [-Expand <string>] [-Force] [-GroupBy <Object>] [-HideTableHeaders] [-InputObje
ct <psobject>] [-ShowError] [-View <string>] [-Wrap] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


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 det
ermines 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 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 parameters.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=113303
Format-List
Format-Wide
Format-Custom

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

C:\PS>get-pssnapin | format-table -auto



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








-------------------------- EXAMPLE 2 --------------------------

C:\PS>get-process | sort-object -property basepriority | format-table -groupby basepriority -wrap



Description
-----------
This command displays the processes on the computer in groups with the same base priority.

The Get-Process cmdlet gets objects representing each process on the computer. The pipeline operator (|) passes the object to the Sort-Object cmd
let, which sorts the objects in order of their base priority.


Another pipeline operator passes the results 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 ensures that data is not truncated.








-------------------------- EXAMPLE 3 --------------------------

C:\PS>get-process | sort-object starttime | format-table -view starttime



Description
-----------
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 cm
dlet to get objects representing the processes on the computer. The pipeline operator (|) sends the output of Get-Process to the Sort-Object cmdl
et, 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 formatting file for System.Diagnostics.P
rocess objects, such as those returned by Get-Process. This view converts the StartTime of the process to a short date and then groups the proces
ses by start date.

The DotNetTypes.format.ps1xml formatting file also contains a Priority view for processes, and you can create your own format.ps1xml files with c
ustomized views.








-------------------------- EXAMPLE 4 --------------------------

C:\PS>get-service | format-table -property Name, DependentServices



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

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








-------------------------- EXAMPLE 5 --------------------------

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



Description
-----------
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 t
o Format-Table, which displays a table with two columns: ProcessName, a standard property of processes, and TotalRunningTime, a calculated proper
ty.

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 --------------------------

C:\PS>$processes = get-wmiobject -ComputerName Server01 win32_process -filter "name='notepad.exe'"

C:\PS> $processes | format-table ProcessName, @{ Label = "Total Running Time"; `
Expression={(get-date) - $_.ConvertToDateTime($_.CreationDate)}}



Description
-----------
These commands are similar to the previous command, except that these commands use the Get-WmiObject cmdlet and the Win32_Process class to displa
y information about Notepad processes on a remote computer.

The first command uses the Get-WmiObject cmdlet to get instances of the Windows Management Instrumentation (WMI) Win32_Process class that describ
es all of the processes on the Server01 computer that are named Notepad.exe. The command stores the process information in the $processes variabl
e.


The second command uses a pipeline operator (|) to send the process information in the $processes variable to the Format-Table cmdlet, which disp
lays the ProcessName of each process along with a new calculated property.

The command assigns the name of the new calculated property, Total Running Time, to the Label key. The script block that is assigned to the Expre
ssion key calculates how long the process has been running by subtracting the creation date of the process from the current date. The Get-Date cm
dlet gets the current date. The ConvertToDateTime method converts the CreationDate property of the Win32_Process object from a WMI CIM_DATETIME o
bject to a Microsoft .NET Framework DateTime object that can be compared with the output of Get-Date. Then, the converted creation date is subtra
cted from the current date. The result is the value of Total Running Time.

The backtick characters (`) are line continuation characters.