PowerShell Module to resize console – Updated
Few days ago I wrote a PowerShell module that contains 1 cmdlet / function to resize the PowerShell console windows.
It was a quick job that I did less than half an hour. I wrote it primarily to make PowerShell Web Access (PSWA) more user friendly.
Over the last couple of days, I spent a bit more time on this module, and add a lot more functionality to it. The original module had 107 lines of code, and the updated one has 591 lines.
Here’s a list of new features:
This module now contains the following cmdlets:
I’ll go through each cmdlets later
Aliases for all cmdlets and parameters
Since I wrote this module primarily for PSWA, and I intend to access PSWA primarily from mobile devices such as phones and tablets, I need to make the module easier to use. I am sure I’m not the only person who’s suffering from fat finger syndrome. I HATE typing on tablets and phones. Even with the Type Cover 2 for my Surface Pro 2, I found the keys are too small. So less is more, aliases really help when I use mobile devices because I don’t have to type as much.
Buffer width is always same as window width when re-sizing
When working on any kind of command prompts (cmd or PowerShell), I really don’t like the horizontal scroll bar. by making the buffer width always the same as window width, I don’t have to see the horizontal bars anymore.
Resize-Console –max switch
Or “rsc –m” if use aliases. The –max switch will move the window to the top left corner of the PRIMARY monitor and maximize the window size. It also set the buffer height to the maximum value of 9999. – This is equivalent to maximizing a normal window.
Every time I get on to a box (most likely via RDP) for the first time, I always had to manually set the PowerShell console size to suit my needs. then next time I RDP in from another computer with different display resolutions, I often had to set it again.
With resize-console –max, it will always set the console to the maximum size and occupies the entire screen. It will make my life so much easier. Not that I have OCD(Obsessive Compulsive Disorder), but for those ones who do, this function would make you much happier I suppose :). I’ll demonstrate this in the Youtube video at the end of this article.
Note: for this functionality, I used some of the code from Richard Siddaways’s blog. So thanks to Richard.
I have included a XML file (profiles.xml) in this module. We can save pre-defined console dimension (Window width and height) to this XML so we can use them later.
The screen size and resolution are different among different computers and mobile devices. I have created different profiles for each type of devices that I own, so when I use a particular device to access PSWA, I can simply apply the appropriate screen size to suit that device.
i.e. the screenshot below is taken from my mobile phone (Samsung Note3):
when I applied the profile “Note3”, the PSWA console fits perfectly on the screen.
Or, on my 10.1 inch tablet Samsung Galaxy Tab2:
I used aliases, applied the “tab2” profile to fit the screen.
With the introduction to the –profile functions, this module now includes these functions for CRUD operations:
For details of each functions, You can refer to the help information (get-help)
Note: only administrators will be able to modify the profiles.xml because it’s located in a system folder. so if UAC is enabled, admins will need launch powershell console as Administrator in order to use the Remove-ConsoleProfile and Update-ConsoleProfile cmdlet.
This one simply display the current window size and buffer size on screen. it’s reading the properties of “$host.ui.rawui”
For your reference, here’s a recorded demo that I have updated to Youtube:
Please watch this video in full screen and 720P/1080P or you may not be able to see what’s happening on the powershell console.
You can download the module HERE. simply unzip and copy the whole folder to C:\Windows\System32\WindowsPowerShell\v1.0\Modules
So why am I spending time on this PowerShell project rather than System Center, which is my bread and butter? That would be the topic for my next blog article. 🙂
Please feel free to contact me for any issues or suggestions.
Until next time, happy PowerShelling 🙂