2

I already know how to modify the window settings in my profile, but the changes take effect after the window already appears so there's a second of time where it appears with the default settings.

I would also like to do this via command-line so I only have to run a windows "initialization script" on a fresh install and have it take effect permanently...therefore using the GUI in the top-left corner is also not acceptable.

wsaxton
  • 1,030
  • 15
  • 34
  • [This answer](http://stackoverflow.com/a/43298114/45375) of mine has code to set the default window with and height for PowerShell console windows - you can adapt it to set color defaults as well. – mklement0 May 07 '17 at 16:44

1 Answers1

2
  • On a new system new users inherit settings from Default/Default User
  • Console settings are stored in the registry in HKCU\Console and subkeys
  • PowerShell console settings deviating from the standard are stored in subkeys:

HKEY_CURRENT_USER\console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe
HKEY_CURRENT_USER\console\%SystemRoot%_SysWOW64_WindowsPowerShell_v1.0_powershell.exe

Aside from this, any shortcut file to PowerShell can store these settings also.

To view current settings run in a Cmd window:

reg query hkcu\console

In PowerShell run:

gci hkcu:Console|where Name -like '*powershell*'|ft -auto

ScreenBufferSize and WindowSize are 32 bit values (REG_DWORD) composed of 16bit height + 16bit width values.

I wrote this batch to decode the sizes:

:: ConsoleSizes.cmd ::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal
echo Window_X*Y_^|_Buffer_X*Y_^|_App-key_____________________________
for /F "tokens=1-2,*" %%A in (
'reg query hkcu\console /s^|findstr "\ ScreenBufferS WindowS"') do (
if "%%B" NEQ "REG_DWORD" (set "HKCUCon=%%A %%B %%C"&set "SBS="&SET "WS=")
if "%%A" EQU "ScreenBufferSize" set "SBS=%%C"
if "%%A" EQU "WindowSize" set "WS=%%C" & call :display)
goto :eof
:display
set /A "WSW=WS&0xffff, WSH=WS>>16"
set "WSW=     %WSW%"&set "WSH=%WSH%     "
set /A "SBW=SBS&0xffff, SBH=SBS>>16"
set "SBW=     %SBW%"&set "SBH=%SBH%     "
set "HKCUCon=%HKCUCon:HKEY_CURRENT_USER=HKCU%"
echo/%WSW:~-5%*%WSH:~,5%^|%SBW:~-5%*%SBH:~,5% ^| %HKCUCon%

Shortened sample output:

Window_X*Y_|_Buffer_X*Y_|_App-key_____________________________
   80*25   |    0*0     | HKCU\console
  132*60   |  132*3000  | HKCU\console\%SystemRoot%_System32_cmd.exe
  120*50   |  120*3000  | HKCU\console\%SystemRoot%_system32_diskpart.exe
  120*50   |  120*300   | HKCU\console\%SystemRoot%_system32_help.exe
  120*50   |  120*3000  | HKCU\console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe
  120*50   |  120*3000  | HKCU\console\%SystemRoot%_SysWOW64_WindowsPowerShell_v1.0_powershell.exe
  120*50   |  120*3050  | HKCU\console\Bitvise ansi terminal
  132*50   |  132*350   | HKCU\console\Bitvise bvterm terminal
  120*50   |  120*3050  | HKCU\console\Bitvise xterm terminal
  132*50   |  132*50    | HKCU\console\C:_Program Files (x86)_Far_Far.exe
  120*50   |  120*50    | HKCU\console\C:_Program Files (x86)_Kinesics_Text_Editor_x64_k.exe
  252*98   |  252*98    | HKCU\console\C:_Program Files_Far_Far.exe

So the short answer is: edit console in default users registry hive.

Additionally, shortcut files that target PowerShell store their own ScreenBufferSize/WindowSize values.

mklement0
  • 382,024
  • 64
  • 607
  • 775