Besides eliminating war and solving world hunger, another of my New Year's resolutions was to use PowerShell as my command window. While you're probably thinking using PowerShell is not much of a resolution, for me it's huge. I do nearly everything related to software development in a command prompt. While I'm not writing my code with a copy con Program.cs, (don't forget the CTRL+Z) I'm not far off. To me a command prompt is where life originates so to consider changing something so fundamental is the equivalent of something this shocking:
Since the DOS 3.3 days, I have lived in 4DOS and 4NT from those great folks from JP Software. In fact, 4DOS was the second program I ever purchased for a computer after Microsoft Word. With the power and speed of 4NT you can do just about anything you could want from a command prompt. It extends the batch programming language to let you write phenomenally useful programs. Its command line editing prowess boggles the mind. For example, if you've been executing a bunch of programs at the command line, entering the first characters of a command and pressing the up arrow cycles through all the commands that start with those characters. That single feature has saved me 10^9 keystrokes over the years. Best of all, 4NT has an excellent batch file debugger so you can easily produce great batch programs that work consistently and correctly. 4NT is up to version 8.0 and I am literally at a loss as to what additional features they could possibly add, but I always upgrade. When I'm teaching a class, nearly the first question I always get when students see me demoing something is "How do you get the command window to that?" Compared to 4NT.EXE, CMD.EXE is from the Jurassic age of computing, AKA 1964. No hyperbole here, 4NT is that much better.
If I like 4NT so much, why would I bother with ever changing? The idea of pipelining items as objects between commands is simply brilliant. It feels like I've written code to parse a million different text files over the years. To be able to treat the output of any command you run as an object is like a dream come true. Throw in for free accessing WMI and the .NET Framework from a command shell and you have something I'm willing to completely destabilize all my muscle memory. That and all the cool kids use PowerShell now.
If you have not looked much at PowerShell, I thought I'd mention the resources and tools I've found to be quite helpful to get started. The first two are books: Bruce Payette's Power Shell in Action, and Lee Holmes' Windows PowerShell Cookbook. While Bruce Payette's book is considered the canonical reference, I learn best by reading over examples that perform things I want to do so Lee Holmes' book really got me into the mindset of PowerShell. Also, thank goodness Microsoft has posted the actual documentation for cmdlets, about, and providers. Scanning help in a command window is so 1970.
A tool that helped me get started was PowerShell Plus. It's basically a live environment with a real editor and debugger for PowerShell. However, I've had to stop using PowerShell Plus because the trial license has expired and thus reverts to "free for non-commercial use." Since everything I do is commercial, I honor the license. Because I'm not so sure I'll keep using PowerShell, which I'll discuss more in a little bit, I'm not ready to plunk down $129 USD for the tool. (As an aside for the developers of PowerShell Plus and PowerShell Analyzer, how about making a clear explanation as to why you have two products that do nearly identical things. The PowerShell debugger in PowerShell Plus is what I want so why should I spend the money to get PowerShell Analyzer too?) Finally, get the truly outstanding PowerTab from Marc van Orsouw, the infamous, /\/\o\/\/! PowerTab adds to the PowerShell command line what Microsoft should have had in the product itself. Also read every one of /\/\o\/\/'s blog entries and you'll learn a ton about what you can do with PowerShell.
Having lived full time in PowerShell for the last ten days, it's been a trip. (I wanted to get a jump on my resolutions.) While I realize that PowerShell is first and foremost geared at network administrators, it was still worth the effort to give it a try. In reading about the PowerShell integration in Exchange 2007, I can actually see network administrators smiling for once as they are receiving some serious Microsoft love. Now that other Microsoft server applications are starting to support PowerShell as well, that's a huge testament to its abilities. While I understand that I'm not in the target demographic for PowerShell, the "everything's a .NET object" mantra is really compelling.
Of course, with any major life change, not everything is totally rosy with PowerShell. One of the biggest hurdles I'm facing as a PowerShell user is that the learning curve is not really step or even vertical, it feels more negative than anything. For example, one of the prime things I want to see as a user is a directory listing that shows me what are junctions, symbolic links, directories, reparse points and so on. Out of the box, PowerShell doesn't show what I want to see when I do a get-childitem on a file directory. I think I have to write something to show that but is it a script, cmdlet, a snap-in, a .PS1XML, or something else I haven't read about? The language and design of PowerShell feel very loose to me. It's being all things to all people so it's very hard to get started. I'm sure I'll eventually figure out how to get a directory listing that actually shows the data you need to see and I think I see a direction to go, but I'll be dropping do 4NT quite a bit until then. On the positive side, being able to search the registry for all matching items easily is a fantastic benefit of the approach PowerShell takes.
A couple of small things have me completely baffled in PowerShell. For example, I use the excellent 7-Zip to compress files. Sadly, whenever I try to execute 7z.exe PowerShell always reports "Bad Numeric Constant" because values can't start with numbers in PowerShell. That definitely falls into the "what were they thinking?" category especially since I always forget to prefix the program name with &. Another thing that's poor is the command line editing. I'm always changing and tweaking previously entered commands. However, when you use the tab completion in the middle of the line, it wipes out the rest of the line. How hard can it be to insert the text from tab completion? Since I'm asking for fixes in the command line editing, how about entering a couple of characters and the up and down history cycling automatically looks for the commands that match the characters entered? Even better, how about adding CTRL+BACKSPACE to delete the previous word on the command line? Just to throw one more in, how about having CTRL+V past in the text on the clipboard? In all, I find myself doing a tremendous amount of additional typing with PowerShell verses 4NT.
My biggest disappointment with PowerShell is the absolutely abysmal script debugging support. I hesitate to call it debugging because without a third party product, you really have no hope of writing anything that's more than "Hello World" in a .PS1 file. Like most developers, I learn best by reading and stepping through code to see what the code does and what the state is at any particular point. Honestly, I'm surprised version 1.0 was released with essentially zero debugging support. Looking at the debugging feature list for PowerShell 2.0, I'm not sure that the debugging support will be much better. Give how extensible the Visual Studio debugger is, I can't believe the team isn't supporting real debugger for scripts.
While it's only been ten days of PowerShell, keep in mind that everything I do is in a command window and have three to four instances of PowerShell running at any given time. It's been lumpy, but I've got fifteen years of barnacles to scrape off my muscle memory and behavior patterns. If I had to put a bet on will I keep my resolution of always using PowerShell, it'd be about 43%. However, there's lots to learn, which always makes this wonderful business we're in fun. As I learn more and become one with PowerShell, I trust it will get easier. I vow to keep using PowerShell through the end of the month so by then I'll have figured out if it's worth the switch or not.On Jan 5 2008 12:12 PMBy jrobbins