If you call formatting cmdlets at the end of the pipeline, you can override the default formatting to control what data is displayed and how that data appears. The formatting cmdlets are Format-List, Format-Table, and Format-Wide. Each has its own distinct output style that differs from the other formatting cmdlets.
Format-List
The Format-List cmdlet takes input from the pipeline and outputs a vertical columned list of all the specified properties of each object. You can specify which properties you want to display by using the Property parameter. If the Format-List cmdlet is called without any parameters specified, all properties are output. The Format-List cmdlet wraps lines instead of truncating them. One of the best uses for the Format-List cmdlet is to override the default output of a cmdlet so that you can retrieve additional or more focused information.
For example, when you call the Get-Mailbox cmdlet, you only see a limited amount of information in table format. If you pipe the output of the Get-Mailbox cmdlet to the Format-List cmdlet and add parameters for the additional or more focused information that you want to view, you can retrieve the output that you want.
You can also specify a wildcard character "*" with a partial property name. If you include a wildcard character, you can match multiple properties without having to type each property name individually. For example, Get-Mailbox | Format-List -Property Email* returns all properties that begin with Email.
The following examples show the different ways that you can view the same data returned by the Get-Mailbox cmdlet.
Get-MailBox TestUser1
Name Alias Server StorageQuota
---- ----- ------ ------------
TestUser1 TestUser1 e12 unlimited
In this first example, the Get-Mailbox cmdlet is called without specific formatting so the default output is in table format and contains a predetermined set of properties.
Get-Mailbox TestUser1 | Format-List -Property Name,Alias,EmailAddresses
Name : TestUser1
Alias : TestUser1
EmailAddresses : {SMTP:TestUser1@contoso.com, X400:c=US;a= ;p=Contoso;o=Exchange;s=TestUser1;}
Get-Mailbox TestUser1 | Format-List -Property Name, Alias, Email*
In the second example, the output of the Get-Mailbox cmdlet is piped to the Format-List cmdlet, together with specific properties. As you can see, the format and content of the output is significantly different.
Name : Test User
Alias : TestUser1
EmailAddresses : {SMTP:TestUser1@contoso.com, X400:c=US;a= ;p=First
Organization;o=Exchange;s=User;g=Test;}
EmailAddressPolicyEnabled : True
In the last example, the output of the Get-Mailbox cmdlet is piped to the Format-List cmdlet as in the second example. However, in the last example, a wildcard character is used to match all properties that start with Email.
If more than one object is passed to the Format-List cmdlet, all specified properties for an object are displayed and grouped by object. The display order depends on the default parameter for the cmdlet. This is most frequently the Name parameter or the Identity parameter. For example, when the Get-Childitem cmdlet is called, the default display order is file names in alphabetical order. To change this behavior, you must call the Format-List cmdlet, together with the GroupBy parameter, and the name of a property value by which you want to group the output. For example, the following command lists all files in a directory and groups these files by extension.
Get-Childitem | Format-List Name,Length -GroupBy Extension
Extension: .xml
Name : Config_01.xml
Length : 5627
Name : Config_02.xml
Length : 3901
Extension: .bmp
Name : Image_01.bmp
Length : 746550
Name : Image_02.bmp
Length : 746550
Extension: .txt
Name : Text_01.txt
Length : 16822
Name : Text_02.txt
Length : 9835
In this example, the Format-List cmdlet has grouped the items by the Extension property that is specified by the GroupBy parameter. You can use the GroupBy parameter with any valid property for the objects in the pipeline stream.
Format-Table
The Format-Table cmdlet lets you display items in a table format with label headers and columns of property data. By default, many cmdlets, such as the Get-Process and Get-Service cmdlets, use the table format for output. Parameters for the Format-Table cmdlet include the Properties and GroupBy parameters. These work exactly as they do with Format-List cmdlet.
The Format-Table cmdlet also uses the Wrap parameter. This enables long lines of property information to display completely instead of truncating at the end of a line. To see how the Wrap parameter is used to display returned information, compare the output of the Get-Command command in the following two examples.
In the first example, when the Get-Command cmdlet is used to display command information about the Get-Process cmdlet, the information for the Definition property is truncated.
Get-Command Get-Process | Format-Table Name,Definition
Name Definition
---- ----------
get-process get-process [[-ProcessName] String[]...
In the second example, the Wrap parameter is added to the command to force the complete contents of the Definition property to display.
Get-Command Get-Process | Format-Table Name,Definition -Wrap
Name Definition
---- ----------
get-process get-process [[-ProcessName] String[]] [
-Verbose] [-Debug] [-ErrorAction Action
Preference] [-ErrorVariable String] [-O
utVariable String] [-OutBuffer Int32]
get-process -Id Int32[] [-Verbose] [-De
bug] [-ErrorAction ActionPreference] [-
ErrorVariable String] [-OutVariable Str
ing] [-OutBuffer Int32]
get-process -Input Process[] [-Verbose]
[-Debug] [-ErrorAction ActionPreferenc
e] [-ErrorVariable String] [-OutVariabl
e String] [-OutBuffer Int32]
As with the Format-List cmdlet, you can also specify a wildcard character "*" with a partial property name. By including a wildcard character, you can match multiple properties without typing each property name individually.
Format-Wide
The Format-Wide cmdlet provides a much simpler output control than the other format cmdlets. By default, the Format-Wide cmdlet tries to display as many columns of property values as possible on a line of output. By adding parameters, you can control the number of columns and how the output space is used.
In the most basic usage, calling the Format-Wide cmdlet without any parameters arranges the output in as many columns as will fit the page. For example, if you run the Get-Childitem cmdlet and pipe its output to the Format-Wide cmdlet, you will see the following display of information:
Get-ChildItem | Format-Wide
Directory: FileSystem::C:\WorkingFolder
Config_01.xml Config_02.xml
Config_03.xml Config_04.xml
Config_05.xml Config_06.xml
Config_07.xml Config_08.xml
Config_09.xml Image_01.bmp
Image_02.bmp Image_03.bmp
Image_04.bmp Image_05.bmp
Image_06.bmp Text_01.txt
Text_02.txt Text_03.txt
Text_04.txt Text_05.txt
Text_06.txt Text_07.txt
Text_08.txt Text_09.txt
Text_10.txt Text_11.txt
Text_12.txt
Generally, calling the Get-Childitem cmdlet without any parameters displays the names of all files in the directory in a table of properties. In this example, by piping the output of the Get-Childitem cmdlet to the Format-Wide cmdlet, the output was displayed in two columns of names. Notice that only one property type can be displayed at a time, specified by a property name that follows the Format-Wide cmdlet. If you add the Autosize parameter, the output is changed from two columns to as many as can fit the screen width.
Get-ChildItem | Format-Wide -AutoSize
Directory: FileSystem::C:\WorkingFolder
Config_01.xml Config_02.xml Config_03.xml Config_04.xml Config_05.xml
Config_06.xml Config_07.xml Config_08.xml Config_09.xml Image_01.bmp
Image_02.bmp Image_03.bmp Image_04.bmp Image_05.bmp Image_06.bmp
Text_01.txt Text_02.txt Text_03.txt Text_04.txt Text_05.txt
Text_06.txt Text_07.txt Text_08.txt Text_09.txt Text_10.txt
Text_11.txt Text_12.txt
In this example, the table is arranged in five columns, instead of two columns. The Column parameter offers more control by letting you specify the maximum number of columns to display information as follows:
Get-ChildItem | Format-Wide -Columns 4
Directory: FileSystem::C:\WorkingFolder
Config_01.xml Config_02.xml Config_03.xml Config_04.xml
Config_05.xml Config_06.xml Config_07.xml Config_08.xml
Config_09.xml Image_01.bmp Image_02.bmp Image_03.bmp
Image_04.bmp Image_05.bmp Image_06.bmp Text_01.txt
Text_02.txt Text_03.txt Text_04.txt Text_05.txt
Text_06.txt Text_07.txt Text_08.txt Text_09.txt
Text_10.txt Text_11.txt Text_12.txt
In this example, the number of columns is forced to four by using the Column parameter.