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.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

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!


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

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.

reports

Powered by Buttondown.

Join me on Mastodon

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

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