Change the PowerShell console size and state programmatically

Being able to change the size of the console window (or any window for that matter) are quick and easy to do using the mouse. The same for changing the window state (for example maximizing a window). But if you want to do this programmatically (for whatever reason) it’s not so simple.

I have created a small function that makes this much easier to accomplish.

The main function (Resize-Console) lets you set a custom Width and Height for the console window, as well as maximize the console, or restore it if it’s already maximized. Note that the custom size only works in a console window, so if you try this in PowerShell ISE it will give you a warning and abort.

The maximize and restore functionality on the other hand, works in both the console and in ISE.

I have also included a couple of small helper functions. The first, Get-ConsoleSize, will just output the current size of the console window, while Get-WindowState will return either ‘Normal‘ or ‘Maximized‘ based on the current state of the window.

As always, holler if you spot any bugs, or have suggestions for future improvements.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s