Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Color My PowerShell World

Posted on November 19, 2020November 19, 2020

I readily admit that I spend a great deal of my day at a PowerShell prompt. My day is very much run from the command-line, and has been for quite some time. This used to be a drab, gray existence. But I've been finding ways to liven things up. Here's one way.

The PSScriptTools module includes a number of custom format files with alternate views. You need to make sure the module is imported before you can use any of them.

Import-Module PSScriptTools

But once loaded, I can run a command like this:

The format view uses a mapping table stored in $PSAnsiFileMap. Files are color-coded based on a type or category. The downside, is that if I want this output I have to remember to pipe to Format-Table and specify the view. But I want this to be the default behavior. Here's how.

First, I need the path to the format.ps1xml file.

$f = (Get-Module PSScriptTools).ExportedFormatFiles | where-object {$_ -match 'filesystem-ansi'}

The value of $f should be something like C:\Program Files\WindowsPowerShell\Modules\psscripttools\2.33.1\formats\filesystem-ansi.format.ps1xml. To make this the default I will run this command.

Update-FormatData -PrependPath $f

The PrependPath parameter tells PowerShell to let this file take precedence. This setting only lasts for as long as PowerShell is running. If I want this behavior all the time, I can put these code snippets in my PowerShell profile script. This will work for both Windows PowerShell and PowerShell 7.

With the new setting, the ANSI-colored view is now my default and I don't have to include any extra steps.

If you'd like to see what other formatting options are in the module, take a look at the README. Nothing is permanent so I hope you'll play, have some fun, and maybe find something that you didn't realize needed!

Share this:

  • Print (Opens in new window) Print

Like this:

Like Loading…

Related

2 thoughts on “Color My PowerShell World”

  1. Daniel says:
    November 20, 2020 at 5:04 am

    Awesome. Thanks!

  2. Pingback: Console Coloration with Powershell – Curated SQL

Comments are closed.

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2026 The Lonely Administrator | Powered by SuperbThemes!
%d