Insights

Setting a row colour in powershell | Format-Table

Setting a row colour in powershell | Format-Table

Setting a row colour in powershell | Format-Table Setting a row colour in powershell | Format-Table
Sitecore MVP & Principal Developer at Valtech
Valtech, UK
Nick Hills

April 17, 2019

This is quite a quick post, but a useful tip. If you are setting up some data in powershell which you then fire at the console via | Format-Table it can be useful to highlight specific rows.

Imagine you have a hashtable with the key as a string, and the value as a number. When you send to the console you will see the names and values set in a table.

Now if you want to set John to be a certain colour then you can use the code below.
Note for static values this doesn’t add much value, we use it for a table that is getting printed dynamically e.g. based on a timer tick and dynamic version of the Name

This requires PowerShell 5.1 or later (check with $PSVersionTable.PSVersion) and doesn’t seem to play fair with the PowerShell ISE, however from a normal PowerShell window or VSCode it works a charm.

Happy colouring!

 

Original article was posted on Boro2g Blog: Setting a row colour in powershell

Meet The Challenges Of Today's Digital Economy

Ready to take that first step and rise to your digital potential? Contact Valtech today.
Talk to Us
Meet The Challenges Of Today's Digital Economy