Specify the size of command prompt when executing a batch file

If you want to change the console font size programmatically, see this page and this page. You basically have to copypaste that module source from the technet page into a new file called SetConsoleFont.psm1 on your local machine. Put it into a folder of the same name without ext (so it becomes SetConsoleFont\SetConsoleFont.psm1). From the command line, powershell -command "echo $env:PSModulePath" to see where you should put that SetConsoleFont\ folder (probably in %userprofile%\Documents\WindowsPowerShell\Modules).

If you want to include that technet script within your batch script and have your batch script create [module_path_dir]\SetConsoleFont\SetConsoleFont.psm1 on the user’s machine, I suggest a batch script heredoc would be an easy way to include it and write it dynamically.

With the module in your module path, you can now use it from the cmd line.

powershell -command "&{set-executionpolicy remotesigned; Import-Module SetConsoleFont; Get-ConsoleFontInfo | Format-Table -AutoSize}"

will show you a table of the font sizes available to your console. Choose one from the nFont column and activate it like this:

powershell -command "&{set-executionpolicy remotesigned; Import-Module SetConsoleFont; Set-ConsoleFont 6}"

If all you want to do is resize the console window and buffer, that’s much simpler. No modules or importing or execution policy overriding is needed. mode con: cols=n1 lines=n2 will change the window dimensions, and there’s a PowerShell one-liner for changing the buffer (scrollback history) size.

:: Resize the console window and increase the buffer to 10000 lines
call :consize 80 33 80 10000

:: put the main part of your bat script here.
:: script
:: script
:: script
:: etc.

goto :EOF

:consize <columns> <lines> <buffercolumns> <bufferlines>
:: change console window dimensions and buffer
mode con: cols=%1 lines=%2
powershell -command "&{$H=get-host;$W=$H.ui.rawui;$B=$W.buffersize;$B.width=%3;$B.height=%4;$W.buffersize=$B;}"
goto :EOF

Leave a Comment