Guy recommends :
Free Firewall Browser

Solarwinds Firewall Browser Free Download

Review firewall settings such as access control lists (ACL), or troubleshoot problems with network address translation (NAT). Free download try it now!


Windows PowerShell Format-Table Cmdlet

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.

Windows PowerShell Format-Table Topics

 ♣

Format-Table - Simple Examples

Scenario: we wish to investigate processes running on workstation or a Windows Server.

Pre-requisites:
PowerShell and .Net framework are installed on your computer.
You are at the prompt PS>  Or if you have PowerShell 2.0, launch the ISE.

Example 1a
Let us get started with an example using the default formatting:

# Preliminary example no Format-Table yet
Get-Process

The 'problem' is that the name of the process is on the right, and we have columns in the output which are of no interest.

PowerShell Format-Table

Example 1b
Now let me introduce Format-Table so that we can control which properties to display in the output.  Let us suppose that we are only interested in 'Handles'.

# Example of PowerShell Format-Table
Get-Process | Format-Table processName, handles -auto

PowerShell Ft

Note 1:  Thanks to Format-Table we now have the name of the process in the first column.

Note 2: -auto prevents the output spreading to the full width and consequently, the -auto parameter makes the figures easier to read.  To see the effect try the above command without -auto.

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v10

SolarWinds' Network Performance Monitor 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.

Perhaps the NPM's best feature is the way it suggests solutions to network problems.  Its second best feature is 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 Solarwinds NPM now.

Download a fully functional free trial of the Network Performance Monitor.

Troubleshooting Format-Table

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

Format-Table comes into its own when dealing with Get-WmiObject classes.  Because the output contains more than 5 properties the default layout is courtesy of Format-List; I find that I like to select my properties then call for Format-Table.

Format-Table - Intermediate Examples

Example 2a:
Time to see which properties of Get-Process are available, then we can fine tune our Format-Table command.

# Example of PowerShell Format-Table for properties
Get-Process | Get-Member -Membertype property

Example 2b: Even here, I cannot resist using Format-Table to filter which column gets exported to the file.

$Proc = Get-Process | Get-Member -Membertype property
$Proc | Format-Table name | Out-File procprop1.txt

Note 3: It's not really necessary to introduce a variable, $Proc. However, one advantage of this technique is that it saves problems with our script word-wrapping to the next line.

Example 3a: Let us choose some different columns in the output, for example, BasePriority and HandleCount:

# Example of PowerShell Format-Table for multiple items
Get-Process | Format-Table name, handlecount, basepriority

Example 3b: Let us see what happens is we add -auto.

# Example of PowerShell Format output for multiple items
Get-Process | Format-Table name, handlecount, basepriority -auto

SolarWinds Firewall Browser Solarwinds Free Firewall Browser

Here is an utility where you can review firewall settings such as access control lists (ACL), or troubleshoot problems with network address translation (NAT).

Other reasons to download this SolarWinds Firewall Browser include managing requests to change your firewall settings, testing firewall rules before you go live, and querying settings with the browser's powerful search options.

Guy recommends that you download a copy of the SolarWinds free Firewall Browser.

Format-Table - Advanced Examples

Sort-object (Can be abbreviated to 'Short')

Example 4:
Suppose you want some order in your output, no problem, call for Sort-object.

$Proc = Get-Process | Sort-Object -descending basepriority
$Proc | Format-Table name, handlecount, basepriority -auto

Note 4: -groupBy This parameter offers a different method of aggregating the data.

Example 5:

Clear-host
$Proc = Get-Process | Sort-Object -descending basepriority
$Proc | Format-Table name, handlecount -groupby basepriority -auto

Note  Out-GridView: PowerShell v 2.0 introduces a new cmdlet to control data display.  See more on how to pipe the results into out-GridView.

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

PowerShell FT Alias Examples

Example 1c [Use in conjunction with Example 1a and 1b above]

# Example of PowerShell Format output with FT
Get-Process | FT processName, handles, PagedMemorySize -auto

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

Example 2c

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 5b:

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.

Guy Recommends:  SolarWinds' Free Bulk Import ToolFree Download Solarwinds Bulk Import Tool

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.

Optionally, you can provide the name of the OU where the new accounts will be born. Download your FREE bulk import tool.

If you need more comprehensive application analysis software,
Download a free trial of SAM (Server & Application Monitor)

PowerShell Format-Table Parameters

We have already seen the -auto parameter, to research more switches try

# Extra parameters for PowerShell to Format output
Clear-host
Get-Help Format-Table -full

One of my favourite Format-Table parameters is -groupBy

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:

Get-Process | Get-Member -Membertype method |format-wide name -column 3.

Format-List

The other way PowerShell can format output is with a list.  This is useful when you want to display multiple properties for one object.  Here is an example:

#Example of PowerShell Format-List
Get-Process services | Format-List -property *

Note 5:  What makes using the format-List worthwhile is the * (star) wildcard.

PowerShell Format-list

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

If you like this page then please share it with your friends

 


See more Microsoft PowerShell output tutorials:

PShell Home   • Out-File   • Out-GridView   • ConvertTo-Csv   • ConvertTo-Html   • ConvertFrom-Csv

Export-CSV   • Import-CSV   • Format-Table   • Format-List   • Files   • Read-Host   • Write-Host

Export-CliXml   • PowerShell 3.0 Redirection   • PowerShell Get-History   • -f format   • Pipe to file

Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


Custom Search

Site Home

Guy Recommends: WMI Monitor for PowershellSolarwinds WMI Monitor

Windows Management Instrumentation (WMI) is most useful for PowerShell scripting.

SolarWinds have produced this Free WMI Monitor to take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor

Author: Guy Thomas Copyright © 1999-2013 Computer Performance LTD All rights reserved.

Please report a broken link, or an error to: