Customizing powershell font face and size

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?


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);