The format table as the name suggests is kind of formatting. The Format table in PowerShell allows you to manipulate the output of cmdlets and functions. Built-in output support of PowerShell does not display all the content and skips a few long lines. The Format table prints the output in an organized tabular form and shows all entries without truncation. This article contains the use of the PowerShell Format Table cmdlet. Moreover, several examples are quoted to better convey the usage of Format Table.
How Format Table Works
The Format-Table cmdlet can be used with any PowerShell object to get its output in a formatted table. The Format Table cmdlet of Windows PowerShell functions on the following syntax:
The parameters supported by this cmdlet are described below:
AutoSize: Using this option, the columns’ width and number will be adjusted according to the data displayed.
DisplayError: This parameter is mostly used for debugging and thus has no such functionality of formatting.
Force: This option is also exercised for debugging and is mostly used with the DisplayError parameter to get the detailed information about the error. Usually, the error information is not in detailed description.
Expand: The collection object and the objects inside the collection object are formatted using this option. This parameter accepts three arguments. EnumOnly displays the properties of collection object only whereas CoreOnly shows the properties of objects in a collection. For getting properties of collection object and objects in collection, you may use Both arguments of the Expand parameter.
Wrap: It shows the content of the column without truncating it. By default, if the content of the table is exceeding the width, then it is truncated.
RepeatHeader: Once the full screen view is obtained. The RepeatHeader parameter shows the header after every full screen view.
HideTableHeaders: The column headings do not show up.
Property: The properties of objects can be displayed using this parameter.
How to use PowerShell Format-Table
This section briefly implements the Format-Table along with the parameters supported by this cmdlet. Firstly, search for “powershell” keyword in the Windows search option on the taskbar and open PowerShell as an administrator.
Example 1: Avoid the Truncation
Let’s say we want to get the content of the Get-command cmdlet. First, execute the Get-Command cmdlet without using Format-Table. It is observed from the output that many entries in the last column are truncated.
Now, pipe the Format-Table cmdlet with Get-Command using the -Wrap option of Format-Table. The output of the below-mentioned command shows that the content of the last column is displayed completely. It is to notice that, the truncation can also be handled using the -Auto parameter for a long truncation. Firstly, we are using the -Wrap option in the below stated command:
Let’s experience the same command with -Auto option:
Example 2: Get the concise output
In some cases, only specific columns are required in the shell. For instance, we have got the output of the Get-Process cmdlet and it is observed that the output contains multiple columns.
Referring to the output shown above, the following Format-Table command would restrict the output to only one column named ProcessName using the -property parameter as shown below.
Example 3: Specifying the property of an object
The Format-Table cmdlet can display the result according to the property of an object. PowerShell allows you to get the supported properties of an object by pressing the tab key after the -Property keyword. The Format-Table cmdlet provided below will print the name and company of each process.
Apart from applying the properties and examples mentioned in this post. You can practice it for more supported parameters provided in this guide.
Before concluding the post, we have a bonus tip for you. The Format-Table cmdlet can also be executed using the FT keyword. The PowerShell command written below performs the Format-Table action using the command can also be executed using the FT keyword.
Conclusion
PowerShell is a windows-based command-line tool to automate and manage several tasks. This article explains the use of Format-Table cmdlet in PowerShell. This PowerShell utility of windows accepts various formatting parameters. It is observed that any PowerShell object can be piped with Format-Table to get the output of that object in a tabular and organized form. It is recommended to practice this useful cmdlet to get the results in a desired format.