private/Step-BuildBootConsoleSettings.ps1

#Requires -PSEdition Core

function Step-BuildBootConsoleSettings {
    <#
    .SYNOPSIS
        Applies console settings to the mounted WinPE default user registry hive
 
    .DESCRIPTION
        Writes a temporary registry file containing CMD and Windows PowerShell console
        font, window, buffer, cursor, and opacity settings. It loads the mounted image's
        DEFAULT hive as HKLM\MountedHive, imports the settings, waits, and unloads the
        hive.
 
    .EXAMPLE
        PS> Step-BuildBootConsoleSettings
 
        Applies the predefined console settings to the mounted WinPE image.
 
    .INPUTS
        None. This function does not accept pipeline input.
 
    .OUTPUTS
        System.String. Returns native stdout emitted by reg.exe LOAD, IMPORT, and UNLOAD.
 
    .NOTES
        Author: David Segura
        Company: Recast Software
        Version: 0.1.0
        Date: 2026-08-28
 
        Requires global BuildMedia.MountPath, reg.exe, write access to TEMP, and access
        to load the mounted DEFAULT hive. Creates TEMP\RegistryConsole.reg and modifies
        the mounted image registry.
    #>

    [CmdletBinding()]
    param ()

    $MountPath = $global:BuildMedia.MountPath

$RegConsole = @'
Windows Registry Editor Version 5.00
 
[HKEY_LOCAL_MACHINE\MountedHive\Console]
"CursorType"=dword:00000000
"FaceName"="Consolas"
"FontFamily"=dword:00000036
"FontSize"=dword:00140000
"FontWeight"=dword:00000190
"WindowAlpha"=dword:000000ff
"WindowPosition"=dword:00000000
 
[HKEY_LOCAL_MACHINE\MountedHive\Console\%SystemRoot%_System32_cmd.exe]
"FaceName"="Consolas"
"ScreenBufferSize"=dword:012c0064
"WindowSize"=dword:001e0064
 
[HKEY_LOCAL_MACHINE\MountedHive\Console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe]
"FaceName"="Consolas"
"FontSize"=dword:00120000
"ScreenBufferSize"=dword:0bb8008c
"WindowSize"=dword:0028008c
'@


    Write-HostDateTimeDarkGray 'Modifying WinPE CMD and PowerShell Console settings'

    $RegConsole | Out-File "$env:TEMP\RegistryConsole.reg" -Encoding ascii -Width 2000 -Force
    reg.exe LOAD HKLM\MountedHive "$MountPath\Windows\System32\Config\DEFAULT"
    reg.exe IMPORT "$env:TEMP\RegistryConsole.reg"
    Start-Sleep -Seconds 3
    reg.exe UNLOAD HKLM\MountedHive
}