Powershell Finally Gives Windows Some Power on the Commandline
I love utility programming: simple software that does something specific to keep you moving on a bigger task. I have a pretty simple rule that I'm always looking for a better and faster way to get any repeated process done. If I have to do something manually twice, you can bet I'm looking for a way to automate all of it or part of it.
Of course, you've got to optimize your time so that you don't spend 2 days automating something that could have been done manually, albeit irritatingly repetitively, in 20 minutes.
Much of the stuff that gets written under the banner of utility programming is done at the command prompt. On UNIX-like systems, bash shell scripting, perl and company are used to pipe text through grep, awk, content is grabbed from the web with wget and log files are rotated, analyzed and munged about with reckless abandon.
On Windows, there has been much weeping and shame over the poor commandline environment that is cmd.exe. Sure, we've had tools like Autohotkey as well as VBScript via WSH, and Cygwin if you were willing to go through the effort, but if you spend your days working on a Windows workstation, you were pretty much set up to get commandline sand kicked in your face at the geek beach (a really scary place, FYI).
Even with those tools, they often felt tacked on. For instance, Cygwin's version of bash has to go through a virtual mounted drive at /cygwin/c to get to your c: drive. It's really not much different than a complete Linux virtual machine sitting on Windows.
Fortunately, cmd.exe has been replaced and the new shell (Powershell) for Windows is a huge improvement not only for those who consider Windows their "home", but for those who find themselves on Windows more as a foreigner in a strange land. If you have spent much time switching between Linux and Windows, you've no doubt typed ls on Windows only to be greeted with an error message and forced to run dir instead. Well, on Powershell, you can do either one and they both do the same thing.
In fact, most of your basic commands from the UNIX world are aliased to their equivalents in Powershell. However, if Powershell was just bash ported to Windows, I wouldn't bother writing about it. Back when it first came out, that's exactly what I thought it was. I even installed it and used it every once in a while. However, only when, a couple of weeks ago I decided to make it my primary shell and really dedicated myself to exploring it, did I start getting excited about it.
Every day that I use this thing, I find more to like about it. And, last Friday, when I had it run a basic program I wrote against Oracle to dump schemas for tables into XML, pipe that XML into an XSLT processor, dump that output into HTML files, combine the HTML files into one, convert it to Word and generate a PDF, all in one command, I knew it was here to stay in my toolkit. I now have a simple script that gives me a PDF documenting the schema of any Oracle database I want (sorry, I can't share as it was done on company time).
To get started, you need to make sure that .NET 2.0 and Service Pack 2 are installed and then install Powershell 1.0.
I'd also recommend installing Console and setting it to use powershell.exe as its shell. Console is a slick front end to Windows command prompts, giving you a tabbed interface, which is really handy when you've got 5-6 shell windows open at once. Console also supports color schemes (which I like) and alpha transparency (which I don't). Of course, I also shut everything "eye candy" related off in Windows except the font smoothing, so what do I know.
Anyway, After installing, you either do a Start->Run->powershell or you start up Console and you'll get your Powershell prompt.
Mess around with it, try out tab completion. Notice how if you're doing a "cd" and hit TAB, it only cycles through directories and not all files (take *that* bash). Notice how it can handle not getting the capitalization right? Get to know it the way you're used to working with cmd.
I'll be back with more on unlocking the power buried inside this plain black and white wrapper (though mostly because this article is growing too large to be put out in one piece).

July 22nd, 2007 at 1:20 pm
Its a shame that I did not know this - yet again. I keep on cursing why windows cmd shell is so poor. though I was right in slamming Microsoft for that, as it lacks basic editing features, basic regex features and God knows what else.
This one is fresh breath of air for me. Thanks for bringing this up. Seems like visiting your blog will improve me in certain key areas.
July 22nd, 2007 at 9:16 pm
Glad you found the information useful. Feel free to subscribe and stick around. I generally share whatever stuff I come across or find interesting. I'm all about sharing information.
June 15th, 2008 at 6:39 am
But the cmd.exe on Vista does tab completion (with only cycling through directories after 'cd'). Also, I have no idea what you are talking about with capitalization, I have never had any problems with that! Basically, leave cmd.exe alone!