When working with Windows Server Core installations where PowerShell is set as the default shell through registry modification, administrators often need to standardize the console appearance across all user sessions. While colors can be set via profile.ps1, font configuration requires a different approach.
The PowerShell console (conhost.exe) stores its font settings in the Windows registry. These settings are user-specific by default, but we can make them machine-wide through registry manipulation:
$consoleRegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console"
$trueTypePath = "$consoleRegPath\TrueTypeFont"
# Create the necessary registry keys if they don't exist
if (-not (Test-Path $trueTypePath)) {
New-Item -Path $trueTypePath -Force | Out-Null
}
# Set default console font (Lucida Console is available on all Windows versions)
Set-ItemProperty -Path $consoleRegPath -Name "FaceName" -Value "Lucida Console"
Set-ItemProperty -Path $consoleRegPath -Name "FontFamily" -Value 0x00000036
Set-ItemProperty -Path $consoleRegPath -Name "FontSize" -Value 0x000e0000
Set-ItemProperty -Path $consoleRegPath -Name "FontWeight" -Value 400
To ensure these settings apply to existing user profiles and new logins, we need to modify the default user registry hive:
# Load default user hive
reg load HKU\DefaultUser "C:\Users\Default\NTUSER.DAT"
# Set console properties in default user profile
reg add "HKU\DefaultUser\Console" /v "FaceName" /t REG_SZ /d "Lucida Console" /f
reg add "HKU\DefaultUser\Console" /v "FontSize" /t REG_DWORD /d 0x000e0000 /f
reg add "HKU\DefaultUser\Console" /v "FontFamily" /t REG_DWORD /d 0x00000036 /f
# Unload default user hive
reg unload HKU\DefaultUser
When PowerShell is launched through a shortcut (as in your registry configuration), we can also modify the shortcut properties:
$shell = New-Object -ComObject WScript.Shell
$shortcut = $shell.CreateShortcut("$env:ProgramData\Microsoft\Windows\Start Menu\Programs\PowerShell.lnk")
$shortcut.TargetPath = "cmd.exe"
$shortcut.Arguments = '/C start /max PowerShell.exe -noExit -Command "mode con: cols=120 lines=50"'
$shortcut.Save()
To confirm the font settings have been applied correctly, you can check the active console properties:
$host.UI.RawUI
Get-ItemProperty "HKCU:\Console" | Select-Object FontSize, FontFamily, FaceName
For modern PowerShell consoles using TrueType fonts, additional registry configuration might be needed:
# Register a TrueType font for console use
New-ItemProperty -Path "$consoleRegPath\TrueTypeFont" -Name "000" -Value "Consolas" -PropertyType String -Force
Set-ItemProperty -Path $consoleRegPath -Name "Terminal" -Value 1 -Type DWORD -Force
When managing Windows Server Core systems where PowerShell is set as the default shell, administrators often need to standardize the console appearance across all user sessions. While we know how to modify the font colors through the profile.ps1 script, persistent font face and size configuration requires a different approach.
The PowerShell console (conhost.exe) stores its font settings in the Windows Registry. Here's how to programmatically modify these settings:
$consoleRegPath = "HKCU:\\Console"
$systemWidePath = "HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Console\\TrueTypeFont"
# Create necessary registry entries if they don't exist
if (-not (Test-Path $consoleRegPath)) {
New-Item -Path $consoleRegPath -Force | Out-Null
}
# Set font preferences
Set-ItemProperty -Path $consoleRegPath -Name "FaceName" -Value "Lucida Console" -Type String
Set-ItemProperty -Path $consoleRegPath -Name "FontFamily" -Value 0x36 -Type DWord
Set-ItemProperty -Path $consoleRegPath -Name "FontSize" -Value 0x00140000 -Type DWord
Set-ItemProperty -Path $consoleRegPath -Name "FontWeight" -Value 400 -Type DWord
# For system-wide application (all users)
if (-not (Test-Path $systemWidePath)) {
New-Item -Path $systemWidePath -Force | Out-Null
}
Set-ItemProperty -Path $systemWidePath -Name "0" -Value "Lucida Console" -Type String
For enterprise environments, you can create a Group Policy Preference (GPP) to deploy these settings:
# Export the registry settings
reg export "HKCU\Console" console_settings.reg
reg export "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont" ttfont_settings.reg
# These .reg files can then be deployed via GPP
Another approach is to modify the PowerShell shortcut properties. This can be done programmatically:
$shell = New-Object -ComObject WScript.Shell
$shortcut = $shell.CreateShortcut("C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Windows PowerShell\\Windows PowerShell.lnk")
$shortcut.TargetPath = "%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
$shortcut.Arguments = "-NoExit -Command "mode con cols=120 lines=50""
$shortcut.Save()
After applying these changes, verify the settings by checking:
Get-ItemProperty -Path "HKCU:\\Console" | Select-Object FaceName, FontSize
Get-ItemProperty -Path "HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Console\\TrueTypeFont"
Remember that some changes might require a new console session to take effect. For Server Core systems, a reboot might be necessary to ensure all user sessions inherit the new settings.