title: Change the PowerShell console font programmatically
body: <p>I've developed a script that acts as a console based application (think ncurses) using PowerShell.</p>
  
  <p>The font <em>Lucida Console</em> is configured within a shortcut to the script.</p>
  
  <p>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': <a href="https://4sysops.com/archives/change-powershell-console-font-size-with-cmdlet/" rel="nofollow noreferrer">https://4sysops.com/archives/change-powershell-console-font-size-with-cmdlet/</a></p>
  
  <p>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 <strong>current</strong> font information.</p>
  
  <p>@sodawillow's comment sent me on the right course. To elaborate...</p>
  
  <p>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).</p>
  
  <p>For example, <em>get-consolefontinfo | format-table</em> returns the following on a window size of 120x64:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Whereas with a window size of 106x51, it returns:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>The font (Consolas, Lucida Console or Raster Fonts) that's applied will differ depending on the index selected.</p>
  
  <p>So contrary to my question, this module does not always reset the font to 'Raster Fonts'.</p>