Register | Login

Stacking Code

public interface IBlog { string Dump(Stream consciousness); }

Zenburn PowerShell

Monday, 14 November, 2011 @ 10:18 PM < Adam Boddington
Tags: PowerShell

When you've got a PowerShell window open all day, the high contrast blue and white can get a little hard on the eyes. I'm currently (re)learning Vim and one of the first plugins I installed was the low contrast Zenburn colour scheme. It would be great if PowerShell had a similar colour scheme.

So how to set that up? It turns out a PowerShell window is capable of displaying any colour, but only sixteen of them at a time. Luckily someone has already figured out what the sixteen colours are for a Zenburn colour scheme, but didn't have much information on how to get them into a PowerShell shortcut.

After a bit of tinkering around on Windows 7 I found a new PowerShell shortcut will take its initial values from HKCU:\Console\<ShortcutName>. If that registry item doesn't exist, it will take them from HKCU:\Console instead. Rather than mess about with the console defaults, I plan to make a new registry item to match the shortcut name.

I've also noticed that once a couple of properties get changed on the shortcut, all the values are internalised (the shortcut size jumps -- mine when from 1.1KB to 1.3KB). At that point it's safe to delete the new registry item and still keep the custom colours.

Sounds a bit complicated -- and it is -- which makes me think there has to be an easier way. Until I find it though, here's a PowerShell script that tries to automate the process as much as possible.

# ZenburnPowerShell.psm1 by Adam Boddington
# Zenburn by Jani Nurminen

function New-ZenburnPowerShell {
    param (
        [string]$Name = $(throw "Name required.")
    $shortcutPath = Join-Path $home "Desktop\$Name.lnk"
    $registryItemPath = Join-Path HKCU:\Console $Name
    # Remove existing shortcut and registry item.
    if (Test-Path $shortcutPath) {
        Remove-Item $shortcutPath
    if (Test-Path $registryItemPath) {
        Remove-Item $registryItemPath
    # Create new shortcut and registry item.
    New-Shortcut $shortcutPath
    New-RegistryItem $registryItemPath
    # Remember the registry item path.
    if (-not $script:registryItemPaths) {
        $script:registryItemPaths = @()
    $script:registryItemPaths += $registryItemPath
    # Instructions for the final steps.
    "Change properties on `"$Name`" to internalise the registry values."
    "Then call Reset-Registry to perform the final cleanup."

function Reset-Registry {
    foreach ($registryItemPath in $script:registryItemPaths) {
        if (Test-Path $registryItemPath) {
            Remove-Item $registryItemPath
            "Removed `"$registryItemPath`""

function New-Shortcut {
    param (
    $ws = New-Object -ComObject
    $shortcut = $ws.CreateShortcut($Path)
    $shortcut.TargetPath = Join-Path $Env:windir System32\WindowsPowerShell\v1.0\powershell.exe
    $shortcut.WorkingDirectory = "%HOMEDRIVE%%HOMEPATH%"
    "Created `"$Path`""

function New-RegistryItem {
    param (
    $x = New-Item $Path
    $colors = @(
        0x003f3f3f, 0x00af6464, 0x00008000, 0x00808000,
        0x00232333, 0x00aa50aa, 0x0000dcdc, 0x00ccdcdc,
        0x008080c0, 0x00ffafaf, 0x007f9f7f, 0x00d3d08c,
        0x007071e3, 0x00c880c8, 0x00afdff0, 0x00ffffff
    for ($index = 0; $index -lt $colors.Length; $index++) {
        $x = New-ItemProperty $Path -Name ("ColorTable" + $index.ToString("00")) -PropertyType DWORD -Value $colors[$index]
    "Created `"$Path`""

Export-ModuleMember New-ZenburnPowerShell, Reset-Registry

It's a module, so put it in Modules\ZenburnPowerShell\ZenburnPowerShell.psm1. Kick it off like this...


At this point there will be a new shortcut on the desktop called Zenburn PowerShell (or whatever name was chosen). Change a few properties on the shortcut, like font and window size (Consolas 16px looks great). Then...


And that's it. A new PowerShell shortcut with the Zenburn colour scheme is born, and the registry is left how it was found.

Zenburn PowerShell

There are 1 comments.


John wrote on Saturday, 18 February, 2012 @ 8:45 PM

Nice. I always wanted good syntax highlighting in PS. And recently just ended up installing the console2 terminal. It works nice for me.

Leave a Comment

Please register or login to leave a comment.

Mercurial Prompt

Visual Studio 2010 and Vim

Mercurial Prompt

Visual Studio 2010 and Vim

browse with Pivot



Building Neno

Recent Posts

Codility Nitrogenium Challenge
OS X Lock
HACT '13
Codility Challenges
Priority Queue


Architecture (13)
Brisbane Flood (1)
Building Neno (38)
C# (4)
Challenges (3)
Collections (1)
Communicator (1)
Concurrency Control (2)
Configuration (1)
CSS (5)
DataAnnotations (2)
Database (1)
DotNetOpenAuth (2)
Entity Framework (1)
FluentNHibernate (2)
Inversion of Control (5)
JavaScript (1)
jQuery (4)
Kata (2)
Linq (7)
Markdown (4)
Mercurial (5)
NHibernate (20)
Ninject (2)
OpenID (3)
OS X (1)
Pivot (6)
PowerShell (8)
Prettify (2)
RSS (1)
Spring (3)
SQL Server (5)
T-SQL (2)
Validation (2)
Vim (1)
Visual Studio (2)
Windows Forms (3)
Windows Service (1)


Powered by Neno, ASP.NET MVC, NHibernate, and small furry mammals. Copyright 2010 - 2011 Adam Boddington.
Version 1.0 Alpha (d9e7e4b68c07), Build Date Sunday, 30 January, 2011 @ 11:37 AM