Customizing powershell font face and size

29,639

Powershell (not the ISE) leverages the "Console Host," which is a slightly more modern update to the ancient MS-DOS command prompt. The Console Host was Microsoft's way of keeping the Command Prompt compatible with modern versions of Windows, but also still compatible with old console apps.

When you launch Powershell.exe, csrss.exe spawns a child process called conhost.exe. This behavior is identical to when you launch Cmd.exe.

But since they had to maintain compatibility with old console apps, they couldn't change the look and feel too much, nor could they go changing and breaking a bunch of internal interfaces.

I'm not going to say that it's impossible, but it is harder than one would think.

There's nothing in (Get-Host).UI.RawUI. There's nothing in the System.Console .NET class.

You could change the font face and size in the registry by doing something like this:

(edit: underscores not slashes)

Set-Location HKCU:\Console
New-Item '.\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe'
Set-Location '.\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe'

New-ItemProperty . FaceName -type STRING -value "Lucida Console"
New-ItemProperty . FontFamily -type DWORD -value 0x00000036
New-ItemProperty . FontSize -type DWORD -value 0x000c0000
New-ItemProperty . FontWeight -type DWORD -value 0x00000190

There are also a bunch of exports in kernel32.dll that change the font:

typedef struct _CONSOLE_FONT {

   DWORD index;

   COORD dim;

} CONSOLE_FONT; 

BOOL WINAPI SetConsoleFont(HANDLE hOutput, DWORD fontIndex);
BOOL WINAPI GetConsoleFontInfo(HANDLE hOutput, BOOL bMaximize, DWORD numFonts, CONSOLE_FONT* info);
DWORD WINAPI GetNumberOfConsoleFonts();
BOOL WINAPI SetConsoleIcon(HICON hIcon);
Share:
29,639

Related videos on Youtube

Brad
Author by

Brad

Updated on September 18, 2022

Comments

  • Brad
    Brad almost 2 years

    We have a number of windows 2012 server core systems with powershell setup as the default shell using the following commands:

    $RegPath = "Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\winlogon"
    Set-ItemProperty -Confirm  -Path $RegPath -Name Shell -Value 'cmd.exe /C start /max PowerShell.exe -noExit'
    

    I've figured out that we can customize the powershell font color with a special powershell script at c:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1. This script gets used by all users.

    However now I want to customize the font face and font size (again for all users) that's persistent. I.E. If I log out of the server and log back in I want the settings to be retained. Likewise if I login as administrator, or my own account powershell should look identical - use the same font color, font face and font size.

    With Powershell ISE it seems possible to set the font face and font size using:

    $psISE.Options.FontName = 'Lucida Sans Console' 
    $psISE.Options.FontSize = 14
    

    Whats the equivalent for powershell itself though?

  • Brad
    Brad over 10 years
    I tried to use the code above to change the font via the registry (but it doesn't seem to have done anything). Is something required for the setting to take effect?
  • Brad
    Brad over 10 years
    Seems like the correct registry keys (at least for windows server 2012) are slightly different Set-Location '.\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.e‌​xe' and Set-Location '.\%SystemRoot%_SysWOW64_WindowsPowerShell_v1.0_powershell.e‌​xe' and it seems like the code is executing but my font doesn't change the powershell console.
  • Brad
    Brad over 10 years
    Using this module: gallery.technet.microsoft.com/scriptcenter/… I was able to change the fonts but it seems the options are very limited. In actuality the fonts available to me either ended up being distorted, too big or too small. I'm trying to figure out how I can select different font sizes.
  • Ryan Ries
    Ryan Ries over 10 years
    Yep, the person who wrote that is PInvoking those exports from kernel32.dll I was talking about. And yes the options are quite limited. That's why when you change the font for any console app through the GUI, you only have 3 font choices. You can't have Comic Sans in your console app, including Powershell. In that guy's script, he's setting the font with Set-ConsoleFont 28. Each font number has a predetermined height and width. Just like when you change it in the GUI.
  • Brad
    Brad over 10 years
    It seems that something as simple as changing the font face and size (which one would assume would be a rudimentary change) is nearly impossible (or at least extremely difficult/with very limited options). So I guess we're stuck with a font size that will cause me to go blind from squinting - thanks Microsoft.
  • CMCDragonkai
    CMCDragonkai over 7 years
    When using regedit to change the facename for HKCU:\Console and the 2 powershell varieties, it never actually changes the font for powershell. I changed facename to Consolas, but powershell stays on Lucida Console. However changes to HKCU:\Console does affect CMD directly. I'm on Windows 10 Anniversary.