PowerShell Server: Changing the Terminal Width

The PowerShell terminal defaults to a width of 80 columns, but sometimes a user will need a larger or smaller display width. Changing the terminal width in PowerShell Server can be easily accomplished with some code similar to the following:

$pshost = Get-Host              # Get the PowerShell Host.
$pswindow = $pshost.UI.RawUI    # Get the PowerShell Host's UI.

$newsize = $pswindow.BufferSize # Get the UI's current Buffer Size.
$newsize.width = 150            # Set the new buffer's width to 150 columns.
$pswindow.buffersize = $newsize # Set the new Buffer Size as active.

$newsize = $pswindow.windowsize # Get the UI's current Window Size.
$newsize.width = 150            # Set the new Window Width to 150 columns.
$pswindow.windowsize = $newsize # Set the new Window Size as active.

Once the above code has been executed, the PowerShell Terminal’s width will be changed to 150 characters. You can, of course, specify any terminal width that you need for your session.

Note: The Window Size cannot be larger than the Buffer Size, so the Buffer Size’s Width must be increased prior to increasing the Window Size’s Width.

You can find more information about altering the PowerShell Terminal’s size at the Hey, Scripting Guy! Blog.

We appreciate your feedback.  If you have any questions, comments, or suggestions about this article please contact our support team at kb@nsoftware.com.