Wednesday, September 06, 2006

Set Window Title in PowerShell

1 It's been a month since my last post, and I'm sure that you were thinking I was dead. Not quite, just really busy. Here's a little time saving tip that I implemented last week in PowerShell. I was working on several issues and had multiple PowerShell windows open. Its kind of hard to find the instance of PowerShell that you are looking for while alt+tabbing through TaskSwitchXP. TaskSwitch even has a preview window, which helps as long as your window isn't minimized. The problem was that I had 3-4 PowerShell windows all titled "Windows PowerShell".

Wouldn't it be great if I could change the window title to something more meaningful? No sweat, PowerShell gives you access to the window through the $Host variable. The command looks like this "$Host.UI.RawUI.WindowTitle = 'My New Title'". Of course, I'll never be able to remember this and it does seem like a lot of typing. So I added the following function and alias statement to my profile.

function Set-WindowTitle($title)
{
$Host.UI.RawUI.WindowTitle = $title
}

set-alias swt Set-WindowTitle

Notice that I tried to mimic the verb-noun convention used by the rest of the PowerShell commands. Now, to set the title I can type in "swt 'My New Title'".

No comments: