5

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 120x64:

nFont dwFontSizeX dwFontSizeY
----- ----------- -----------
0          84           42
1          70           48
2          52           64
3          105          64
4          105          64
5          120          64
6          120          64
7          168          64
8          52           96
9          105          96
10         140          96
11         210          128

Whereas with a window size of 106x51, it returns:

nFont dwFontSizeX dwFontSizeY
----- ----------- -----------
0          104          49
1          114          49
2          125          49
3          104          55
4          78           73
5          156          73
6          179          73
7          250          73
8          78           110
9          156          110
10         209          110
11         313          147

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'.

3
  • I've tried this, and I cannot get the Set-ConsoleFont function to work from the module at all. Is any of this working in 2022, and if not, does anyone have a way to do this (as I'm quite interested in getting this working)?
    – YorSubs
    Commented Oct 2, 2022 at 9:06
  • In addition to the above link, there is also this discussion, learn.microsoft.com/en-gb/samples/browse/…
    – YorSubs
    Commented Oct 2, 2022 at 9:07
  • Set-ConsoleFont does not work for PowerShell 7.x or Windows Powershell 5.1. The module will load, but neither command functions. Commented Nov 23, 2022 at 18:58

1 Answer 1

1

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

Set-ConsoleFont 1 #Raster Fonts
...
Set-ConsoleFont 9 #Raster Fonts
Set-ConsoleFont 10 #Consolas
Set-ConsoleFont 11 #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.

1
  • I've tried this, and I cannot get the Set-ConsoleFont function to work from the module at all. Is any of this working in 2022, and if not, does anyone have a way to do this (as I'm quite interested in getting this working)?
    – YorSubs
    Commented Oct 2, 2022 at 9:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.