PowerShell Tip – Custom windows for different tasks.


There seems to be a lot of articles around at the moment concerning the use of PowerShell.

I think this is great and I’m currently attempting to write a PowerShell script for all of the activities that I perform daily on my databases.

However, anybody who has more than a few scripting windows open at time, will soon notice that it becomes quite a chore identifying what has been running in that window (or perhaps what is still running.)

One simple way that I’ve recently noticed people doing is to customize the PowerShell Session, changing the foreground and background colours as well as the title of the window.

For example, say we have a window that we are just using to preform backups in.

We might change the title of the window to “Server backups” and possibly the background colour to blue and the text colour to white (or whatever floats your boat.)

There’s a whole heap of customizations that can be made.

Here’s a small sample to illustrate what I mean with a script that changes a few properties of the window.

$a = (Get-Host).UI.RawUI
$a.BackgroundColor = “Blue”
$a.ForegroundColor = “White”
$a.WindowTitle = “Server Backups”

Quick visual indicators are always good.

This may be a simple tip, but I’ve found that it works well for me, and I hope it helps somebody else out. I’d be interested to hear if you like it.




About Martin Catherall

Martin Catherall is Senior SQL consultant at SQL Down Under, based in Melbourne, Australia. Martin is also a Microsoft Data Platform MVP and Regional Mentor (RM) for the Professional Association for SQL Server. Prior to relocating to Australia he was extremely active in the Christchurch, New Zealand data community - founding the local SQL Server user group and organizing SQL Saturday Christchurch - which later became SQL Saturday South Island. He likes learning interesting stuff about processing and storing data and passing on his knowledge. In his spare time he likes to learn guitar and hang out with his two young sons Callum Glen and Robert Michael.