October 15th, 2006

Windows PowerShell Font Customization

PowerShell Team
PowerShell Team

Windows PowerShell Font Customization

 

<Today we have a guest blog entry from another team in Microsoft>

There’s a new set of fonts that have been developed and released this year bundled with the betas for the new Windows and Office.  These 6 fonts are collectively called The Microsoft ClearType Font Collection.  They are designed for on-screen reading with ClearType enabled.  In short, this means that if you have an LCD display then text written in these fonts will be more readable.  One of these fonts in particular, Consolas, is of interest to us programmers, shell scripters and IT folk.  Consolas is described as “a monospaced font (like an old typewriter) and good for programmers setting code (its core purpose).”  We’re going to install it for use in PowerShell.

First of all, you need to obtain the font.  If you have the Windows Vista beta or the Office 2007 beta, you already have it.  If you have a licensed copy of Visual Studio 2005, you can download the Consolas font for free.  Another prerequisite is to enable ClearType on your LCD.  If ClearType is not enabled then Consolas will actually look worse than using the default fonts!

The next step, once the font is installed, is to register it for use in the Console.  You can run the PS script below (provided by Lee Dohm) as an administrator or you can follow the manual steps in KB article Q247815.

You then need to log out (on Vista) or reboot on XP (log out might be sufficient but I haven’t tried it.)  Then open up a console, click the control box (upper left corner of the window) and choose Properties.  The Font tab contains a list of Console-enabled fonts including the new entry, Consolas.  Choose it, pick a nice size for it and click Ok.

$key = “HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont”
 
## Find out if Consolas is installed on the system
if(!(test-path (join-path $env:windir “Fonts\CONSOLA.TTF”)))
{
        write-host “The Consolas font is not installed on the system.”
        write-host “Install Microsoft Office 2007 Beta to obtain the font.”
        break
}
 
## Determine if Consolas is already installed as a command window font
$installed = get-itemproperty $key |
             get-member |
             where-object { $_.Name -match “^0+$” } |
             where-object { $_.Definition -match “Consolas” }
if($installed -ne $null)
{
        write-host “The Consolas font is already installed as a command window font.”
        break
}
 
## Find out what the largest string of zeros is
$zeros = (get-itemproperty $key |
         get-member |
         where-object { $_.Name -match “^0+$” } |
         measure-object).Count
 
## Install the font
new-itemproperty $key -Name (“0” * ($zeros + 1)) -Type string -Value “Consolas”
write-host “Consolas font installed successfully as a command window font.”

 

Aaron Lieberman is a developer at Bungie Studios focused on user interface and networking.
Lee Dohm is a developer in MSTV Engineering Services Build & Tools and wrote the script.

 

Category
PowerShell

Author

PowerShell Team
PowerShell Team

PowerShell is a task-based command-line shell and scripting language built on .NET. PowerShell helps system administrators and power-users rapidly automate tasks that manage operating systems (Linux, macOS, and Windows) and processes.

0 comments

Discussion are closed.