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
Wow, I think it's a huge complement to PowerShell that you would even consider trying it out! :)
You have some great usability feedback. They're toying with a new WPF-based console (which I'm not a fan of) but whatever they do I hope they improve the usability of the CLI, just because they can, if for no other reason!
I do wonder if they've tried to avoid a Visual Studio integration for debugging because of the IT "admin" target, which typically wouldn't have VS available or installed.
Anyway, I hope the rest of the month goes well for you - and who knows, maybe your final answer will be "both". Living in 4NT for daily stuff, and switching to PowerShell for parsing tasks or other things it does better. Seems like that'd be a pain though. :)
Oh, and while it'll change your muscle memory a little, you could create an alias for 7z.exe - like "zip" or something:
"Set-Alias zip 7z.exe"
One benefit to that is that you could swap out 7zip for another zip utility without having to change all your scripts (possibly - if cmd line options line up). For that matter, you could wrap it in a function to "abstract" it out. That's probably overkill though.
Have you tried PowerGUI?
Free and nice step through debugging.
http://powergui.org/downloads.jspa
I took a similar path as you except I did it last year. I tool purchased 4DOS years ago, then 4NT loved both of them, however, the alure of PowerShell was enough that last year I took the plunge and tried to make PS my primary command line environment.
After about 10 months I have to say it still is. Here are a copule key tips I lurned....
1. Install PowerShell Community Extensions http://www.codeplex.com/PowerShellCX - the functionality that comes with this is a great help as is looking at what/how they have implemented that functionality
2. Spend the time to setup a profile, get the aliases and functions you want setup. I also use 7-Zip and have use a similar approach to the first commenter above, however, instead of an alias, I use a function that I can pass parameters to. this lets me use default values for common parameters that I always use which can't be done in PS.
Overall you are right, the command line editing story in v1 of PS is terrible when compared to 4NT. I have not looked at it but it *might* be better in v2. However, even with those limitations I have found the capabilities of PS enought that I have pretty much totally moved over to it from 4NT. I still have 4NT installed but its been months since I have used it.
I agree that PSH is a nice technology and feature-wise is a massive improvement over cmd.exe and WSH. However, there are two things that keep me from using it: Performance and memory usage.
On my dualcore 1,8 Ghz machine with 3 gigs of RAM, spawning a new PSH console takes 5-10 seconds. 5 to 10 seconds! Even worse, each process consumes about 41 MB of private bytes (cmd.exe requires 1.5 MB). I consider this inacceptible -- I tend to have 5 to 10 cmd.exe consoles running in parallel. Also, I frequently open a console from Explorer (open command prompt here), quickly execute a command and close the console. Given these usage scenarios, such a long startup time and the amount of memory consumed renders PSH pretty much unusable for me -- I will probably continue using cmd.exe (with unxutils) for quite some time to come. As cool as a new product may be, if its performance sucks, the product sucks.
Howdy John!
10,000 thanks for taking the time to write up a thoughtful review! I cannot tell you how valuable the team finds it when people document what they don't like about PowerShell. We use this to prioritize changes in the next version.
I'll respond to a couple points.
First - J. Passing said
> On my dualcore 1,8 Ghz machine with 3 gigs of RAM, spawning a new PSH console takes 5-10 seconds.
I'll bet you a dollar that if you run my Update-Gac.ps1 script - it will get MUCH faster: http://blogs.msdn.com/powershell/archive/2007/11/08/update-gac-ps1.aspx
Give that a try and let me know what happens. (it won't help memory consumption but your startup and run times should get dramatically improved).
> My biggest disappointment with PowerShell is the absolutely abysmal script debugging support.
In V1 we have SET-PSDEBUG.
-TRACE lets you trace scripts.
-STEP lets you single-step scripts.
Actually you might want to check out a series of blogs we did on how to debug V1 at: http://blogs.msdn.com/monad/search.aspx?q=debugging&p=1
Still, your point is taken: debugging needs to be dramatically improved. I'm actually wildly optimistic about the debugging of V2 (you can see the beginnings of this in the CTP) but what I think you are looking for is a visual debugger. Right now we are focused on the infrastructure so that anyone can write a great visual debugger. That said, we expect (hope?) to support visual debugging with our Graphical PowerShell in V2.
re: 7zip.exe - "what where they thinking".
That is a bug.
RE: Tab Expansion.
This one falls into the "to ship is to choose" bucket. We did a little bit here and then made it possible for others like MOW to replace us.
Again - thanks for the feedback and sorry for your headaches. I hope you get over the hump and become an active V1 user but if you don't, I hope you'll give it another look with V2. In either case, please continue to document your headaches and disappointments and we'll use that to make future products better.
Cheers!
Jeffrey Snover [MSFT]
Windows Management Partner Architect
Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx
I'm also a software developer and have been using PowerShell daily for over two years now. I use it heavily for search&replace operations in source code, analyzing VS solutions (does the source file directory structure match the namespaces), etc. PowerShell is also great as a .NET REPL - effectively eliminated a whole lot of ConsoleApplication42 experiments e.g. need to know how this string "11/1/01" will get parse by System.DateTime:
PS> [System.DateTime]::Parse("11/1/01")
Thursday, November 01, 2001 12:00:00 AM
There is a lot to like with PowerShell but there are some things that can trip you up *some* of which you have found. :-) I've written up a series of Effective PowerShell posts (1..10) that you might find helpful at http://keithhill.spaces.live.com. If you check out the post Effective PowerShell Item 10: Understanding PowerShell Parsing Modes you'll see why executing 7z.exe needs to be executed like so:
PS> & 7z.exe
I second the recommendation to give the PowerShell community extensions a try (although I'm a bit biased as the project coordinator). It fleshes out the utility cmdlets with stuff like out-clipboard (get-clipboard), format-hex, format-xml, select-xml, test-assembly, get-peheader, new-hardlink, new-junction, new-symlink, set-filetime, get-shortpath, get-hash, send-smtpmail, start-process, etc. I like to think of it as my (eventual) replacement for the MKS Toolkit utilities. You can download it from http://www.codeplex.com/powershellcx.
Oh yeah, I also wanted to second the recommendation to try PowerGUI script editor. It's debugging abilities are still in beta form but they're promising.
On Windows Vista (I use x64 but I think x86 is the same) you can no longer drag and drop a file from Explorer to cmd.exe, which was a very useful way of pasting full paths in XP. (as described by Raymond Chen http://blogs.msdn.com/oldnewthing/archive/2007/12/31/6909007.aspx)
I've just installed PowerShell and 4NT, and note that both of these are also missing this feature in Vista.
Is there any possibility of adding drag and drop of file names from Explorer to Powershell.
Many thanks,
Ian.
In my continued resolution to make PowerShell my full time command line interface, I've been porting
John, I am sorry we did not communicate this right: PowerShell Plus is free for both private and commercial use at this point. There will be some sort of (reasonable) license fees when the final is released to cover dev costs (we are a small honest shop and need to pay for our work).
I take your suggestion though and will change the misleading license statements accordingly in one of the next beta releases.
I am glad you like our debugger, and I am sure we added a ton of other useful features in the meantime. So if you continue to go the PowerShell path, I would be more than glad to have you as a PS+ user ;-)
All the best
Tobias
As I wrote a little bit ago my New Year's resolution was to see if I could make PowerShell my full time
Hi John,
I took your post as inspiration to go and create an incremental 7zip backup script using and didn't come across the same problems you did. Feel free to go grab the script and have a look.
http://wmug.co.uk/blogs/sean/archive/2009/03/20/powershell-amp-7zip-incremental-backup-solution.aspx
Thanks
Sean
Sean,
Glad I could be inspiration! :) The problem I was running into was I was trying to execute "7z" directly at the PowerShell command line. Your excellent script uses the complete path so it doesn't run into the problem.
Hope it helps!
- John Robbins
Love the blog!
I've been using 4nt since NT 3.51 myself. The two most used things are ffind and list. I too am used to the command line tabbing and expansions, and heavily use them. I'm so used to type "list" enter a couple of chars hit tab and F to search for a string ...
If they improve the line completion chars as you mention and I can find a char mode search / display / hex edit mod (or I wrote a .Net version!) I'd probably switch.
I hope jpsoft is thinking about PowerShell. Would love to see an unholy marriage between both!