Change the PowerShell console font programmatically

Question:

I’ve developed a script that acts as a console based application (think ncurses) using PowerShell.

The font Lucida Console is configured within a shortcut to the script.

I’d like to provide the user with the ability to change the font size. The following module does just that, however the font is always reset to ‘Raster Fonts’: https://4sysops.com/archives/change-powershell-console-font-size-with-cmdlet/

I don’t understand why this happens, as the code appears to produce the list of legal font sizes based on a reference to the current font information.

@sodawillow’s comment sent me on the right course. To elaborate…

It appears that list of valid font sizes is determined by the console window size (there may also be other factors that I have failed to consider).

For example, get-consolefontinfo | format-table returns the following on a window size of 120×64:

Whereas with a window size of 106×51, it returns:

The font (Consolas, Lucida Console or Raster Fonts) that’s applied will differ depending on the index selected.

So contrary to my question, this module does not always reset the font to ‘Raster Fonts’.

Answer:

I did some testing. I think you cannot directly change the size with this module (my default console font is Consolas):

the code appears to produce the list of legal font sizes based on a
reference to the current font information.

According to the module’s description:

Get-ConsoleFontInfo

List current console’s available fonts.

Source:

Change the PowerShell console font programmatically by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply