Windows PowerShell Scripting – Format-Table (FT)

Format-Table, or FT for short, controls the formatting of the output of your Windows PowerShell commands. Whenever presentation of information is important, pipe the script’s output into Format-Table. On this page I will show you examples of this straightforward, but important command.

SolarWinds Network Performance Monitor (NPM) will help you discover what’s happening on your network. This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems. Its also has the ability to monitor the health of individual VMware virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM on a 30-day free trial.

Troubleshooting Format-Table

The main thing that goes wrong with Format-Table is forgetting the pipe (|) before the command. My technique is to get the main command working then use (|) to pipe the output into Format-Table. From there we can list the names of the properties we wish to display.

A secondary problem with this cmdlet is forgetting the comma between the properties; but remember, there is no comma after Format-Table and before the 1st property.

This Engineer’s Toolset provides a comprehensive console of 50 utilities for troubleshooting computer problems. Guy says it helps me monitor what’s occurring on the network, and each tool teaches me more about how the underlying system operates.

There are so many good gadgets; it’s like having free rein of a sweetshop. Thankfully the utilities are displayed logically: monitoring, network discovery, diagnostic, and Cisco tools. Try the SolarWinds Engineer’s Toolset on a 14-day free trial now!

Format-Table with Get-WmiObject

Format-Table comes into its own when dealing with Get-WmiObject classes. Because the output contains more than 5 properties, and the default layout is courtesy of Format-List; I prefer to select my properties, and use Format-Table.

Format-Table Alias FT

With Microsoft, there are always at least three ways of doing everything, what seems like redundancy when you are an expert, seems like perspective when you are a beginner. One obvious example is that you can abbreviate Format-Table to FT. As you increase your range of PowerShell commands, keep an eye out for another PowerShell Alias, for example, gwmi for Get-WmiObject and gci (Get-Childitem).

Here are alternative methods of achieving the above objectives, each example is designed to develop your binocular vision, hence see the target more clearly. For example, if you experiment with format-wide and format-List you will extend your range of formatting options.

Import users from a spreadsheet. Just provide a list of the users with their fields in the top row, and save as .csv file. Then launch this FREE utility and match your fields with AD’s attributes, click and import the users.

PowerShell FT Alias Examples

Learning points. You can substitute FT for Format-Table. Also you can research other properties, for example PagedMemorySize.

Example 7b:

Clear-host
Get-Process | Get-Member -Membertype method | FT name

Learning points. In addition to property, you can research an object’s method. For instance, in other scripts you may wish to employ the .kill() method.

Example 7c:

Get-Process | FT Name, HandleCount -groupby BasePriority -auto

Learning points. It’s not essential to use variables. This is a simpler example focusing on the -groupby switch.

Format-Wide Cmdlet

How to Discover More Formatting Cmdlets

Clear-Host
Get-Command -verb format

In addition to Format-Table, you can display data in not one column but two or three columns. This is the format-wide or (fw) option, which is useful where you have a long list with only one field, for example:

Script (cmdlet) Technique

As regards our working technique for Format-Table, we have reached a crossroads. My preferred working method is to create scripts and then run them from the PowerShell command line. The other alternative is to keep typing and re-typing the commands in the shell. My technique comes into its own when the commands are complex; as a bonus, my scripts document what I do so it’s easy to refer and refine previous experiments.

If you too like this script (cmdlet) method, then first make sure PowerShell will allow the script to run, you only have to do this once, type :Set-ExecutionPolicy RemoteSigned

Assuming that I have saved example 2 in a file called proc.ps1, what I do is go to the PS prompt and type .\proc. You either have to save the script into the working directory, or else use cd to change to the directory where the script was saved.

»

Summary of Format-Table in Windows PowerShell

Presentation really does transform the output of your PowerShell scripts. Also, when you get too much information the answer is to filter and reduce the number of columns in the display. On other occasions, you need to display extra properties, which are not shown by the default command. In each case, Format-Table gives you control over the presentation of your output.

While Format-Table (or FT for short), is a ubiquitous command, it does have numerous switches. With judicious application of its many switches, you can produce creative and effective outputs.