Powershell: Feature Request: Add conditional colorization to Format-Table command

Created on 30 May 2017  路  3Comments  路  Source: PowerShell/PowerShell

The Format-Table command in PowerShell displays objects in a fundamentally similar manner as Microsoft Excel spreadsheets. Microsoft Excel provides a conditional formatting feature that enables spreadsheet builders to change the display format of a cell, based on the value of the cell's contents.

It would be really great if a PowerShell user could add conditional formatting rules to object properties, using the Format-Table command. That way, let's say you have an object with a Status property. That property could be emitted as Green if its value is Success or Red if the property value is Failed.

Name   Status
----   ------
Step 1 Failed (Red)
Step 2 Success (Green)

For example, you could add a custom property specifier in the Format-Table command as follows:

Get-SomeObjects | Format-Table -Property Name, @{ Name = 'Status'; Color = 'Green'; Value = '^Success$' }

In PowerShell today, we already have a similar syntax for building "calculated properties." We could leverage a similar syntax to build colorized expressions in data tables. This capability would be useful to build PowerShell-based dashboards and presenting data in a more useful manner in the console.

Cheers,
Trevor Sullivan

Issue-Enhancement WG-Engine

Most helpful comment

Ditto for Format-Custom, Format-List and Format-Wide

All 3 comments

Definitely a future enhancement, but I agree this would be awesome.

Ditto for Format-Custom, Format-List and Format-Wide

For anyone wanting this today, Ahmad Adel Gad has offered a solution, Write-PSObject, on TechNet's Script Center. https://gallery.technet.microsoft.com/scriptcenter/Format-Table-Colors-in-e0a4beac

For conditional formatting, see example 16B.01: Write-PSObject $servers -MatchMethod Exact -Column * -Value $false -ValueForeColor Red;

There's some really good thought into the options available on this CmdLet, so could be a good source of inspiration for this enhancement request too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JohnLBevan picture JohnLBevan  路  3Comments

rudolfvesely picture rudolfvesely  路  3Comments

aragula12 picture aragula12  路  3Comments

alx9r picture alx9r  路  3Comments

MaximoTrinidad picture MaximoTrinidad  路  3Comments