Windows Tip Sheet

Color My World

Cure PowerShell's Color-blindness with this quick tip.

This week I have another PowerShell tip that might help you make the transition from the old command shell. One feature I like in the CMD shell is Color. This command lets me change the background and font color of my window. Since I'm likely to have several command windows open at once, using different color schemes helps me stay organized.

While PowerShell can execute many CMD programs, it can't recognize Color. However, I can work around that limitation by adding this function and alias to my PowerShell profile:

function Get-color {
Param ([string]$scheme)
cmd.exe /c color $scheme

Set-Alias color Get-color

The Get-color function takes a run time parameter I call $scheme. In the CMD shell, this parameter is the color attribute I want to set for the console such as "fc," which will produce a light-red font on a white background. You can also use the /? switch to display help and get other properties for $scheme.

Get-color actually calls the CMD shell and runs the color command. The alias is the same as the CMD command, so you don't have to learn anything new. The beauty of this is that Windows goes ahead and applies the color scheme to the PowerShell console window.

Tech Help—Just An
E-Mail Away

Got a Windows, Exchange or virtualization question or need troubleshooting help? Or maybe you want a better explanation than provided in the manuals? Describe your dilemma in an e-mail to the editors at [email protected]; the best questions get answered in this column and garner the questioner with a nifty Redmond T-shirt.

When you send your questions, please include your full first and last name, location, certifications (if any) with your message. (If you prefer to remain anonymous, specify this in your message, but submit the requested information for verification purposes.)

Be aware of some of its limitations. In the CMD shell, running color again without any parameters restores the original color scheme. This does not work with my PowerShell function. There is a way to query the PowerShell console to get the current colors, but the colors are listed as names and the color command, oddly enough, uses codes. Not that it couldn't be done, but I'll leave that as an exercise for you. I'll even give you a a hint: $host.ui.rawui.

About the Author

Jeffery Hicks is an IT veteran with over 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He is a multi-year recipient of the Microsoft MVP Award in Windows PowerShell. He works today as an independent author, trainer and consultant. Jeff has written for numerous online sites and print publications, is a contributing editor at, and a frequent speaker at technology conferences and user groups.

comments powered by Disqus
Most   Popular