Windows PowerShell in Action 442
jlcopeland writes "For two decades I've hated the command prompt in DOS and Windows.
Inconsistencies abound and everything is a special case. The
fallback on a Microsoft box has been running a Unix shell under Cygwin or
installing Microsoft's
own Services for Unix (or its predecessor, Softway's Interix),
or by scripting in Perl, but those only get
you so far. Having co-written nine years worth of trade rag columns
using mostly Perl as the implementation language for the samples,
and thinking of every problem that comes across
my desk as an excuse to write a little bit of scripting code,
I've got some well-formed views about scripting languages
and what works and what doesn't. That means
I've been eagerly watching the development of PowerShell since it
was called Monad. It's got the advantage of being a unified command-line
interface and scripting language for Windows, even if it does have
a dorky name." Read the rest of Jeffrey's review.
Windows PowerShell in Action | |
author | Bruce Payette |
pages | 576 |
publisher | Manning |
rating | 9 |
reviewer | Jeffrey Copeland |
ISBN | 1932394907 |
summary | Guide to PowerShell, the new Windows scripting language |
Bruce Payette's Windows PowerShell in Action is a great overview of PowerShell, aimed at an audience that's got some experience with other scripting languages. Bruce's book is a big improvement over Andy Oakley's earlier book, Monad, which I had been using: it's more complete and it's up-to-date for the first release of PowerShell. It's got great (and sometimes amusing) examples, and feels like the Perl Camel book in flow. When I was reading it in the gym or someplace else away from the keyboard, I kept wanting to run back to the office to try something out. There are also useful "why it works this way" digressions, which provide a lot of context. Since Bruce was on the original development team, wrote most of the commandlets, and was responsible for much of the language design, those digressions are more authoratitive than the directors' commentary tracks on most DVDs.
In outline, the nine chapters in the first part of the book build up as you'd expect: overview and concepts, to data types, to operators, to regular expressions, to syntax, to functions, to interpreting errors. It covers that ground better than many language books that now litter my shelves. The explanations are clear, and the examples are almost all exactly on point. It took me a second reading to realize that my complaints about the regular expression sub-chapter wasn't about the chapter itself, but about some of the implementation decisions; that's an argument about style more than substance, and an observation about me, not about Bruce's writing or PowerShell. The first part of the book is the "mandatory reading," if you will, to get the language down and begin exploring on your own.
The second part is where the real applications are covered. That's the part that you especially want to read sitting next to the keyboard. As you'd expect, the example code is available from the publisher's web site to start you off — look for "Example Code" under "Resources." There's a very good discussion of text processing and how-to-handle XML, complete with some not-obvious warnings about traps to avoid. I've been working very carefully through the really good chapter on using GUIs with PowerShell, "Getting Fancy — .NET and WinForms," and my own proof of concept for that has been rebuilding an old C++ data entry application into a much simpler PowerShell script. As a nice side effect, Bruce's book (and the WinForms chapter in particular) provide a gentle overview to some concepts in the .NET framework, which I hadn't had an opportunity to delve into. The appendix on using PowerShell as a management application will be especially useful to system managers; that was one of the original PoweShell target audiences, and the language achieved that goal very well. The appendix on the language's grammar is really useful, and I keep flipping back to it to check on things.
After Oakley's Monad appeared, there was a long gap before the next PowerShell book appeared. Bruce's book looks to be the first of the post-release wave. If all it had going for it was the authoratative pedigree of the writer, it might be worth it, but it's also well-written, well-organized, and thorough, which I think makes it invaluable as both a learning tool and a reference.
You can purchase Windows PowerShell in Action from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Re:Don't knock it until you try it (Score:5, Informative)
Unless MS rewrites all of their other commands to accept STDIN/OUT, Monad will never surpass the shells. The power of the shells isnt' their programming flexibility, it's their ability to incorporate all the other UNIX tools and commands via pipes to do what you want.
Another reason it will never surpass the shells. They're lightweight, and flexible, and I don't need a Garbage Collector running in the back end to clean up my object allocation.
Re:At this rate... (Score:4, Informative)
"Those who do not understand Unix are condemned to reinvent it, poorly"
Re:At this rate... (Score:4, Informative)
Re:At this rate... (Score:4, Informative)
Wake me up when *nix gets an object-oriented (rather than text-oriented) shell. Because that is what makes Powershell so unique. Yes, it has plenty of builtin functions to make tasks easier, but the real advantage is that everything you pass between commands is an object.
You don't have to worry about interpreting text output - you just access whatever data you want directly. Many of the commands are easily chainable into something like "ls | select fullname,length | sort name | format-list | out-printer".
Re:Don't knock it until you try it (Score:2, Informative)
Let's see on my Mac with OS X, my bash shells, which admittedly aren't being used semi-heavily, are using:
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
nobody 879 0.7 -0.0 27816 856 p3 Ss 11:06AM 0:00.12 bash
nobody 281 0.0 -0.1 27816 1472 p1 S+ 11:09PM 0:00.17 -bash
nobody 348 0.0 -0.0 27816 904 p2 S+ 11:37PM 0:00.16 -bash
Hmmm... that comes to an average of 1078kb of memory per shell. And PowerShell can use up to a GIGABYTE?
I'm still laughing.
What about MKS? (Score:3, Informative)
Re:Monad (Score:2, Informative)
There is all you need.
Re:It's amazing people still use windows. (Score:2, Informative)
Re:Don't knock it until you try it (Score:5, Informative)
It really fails in two places. Firstly, it's slow. You wouldn't have thought it possible for a command shell to be that slow, but it is. It's so slow it was actually quicker for me to use explorer. It is god-awfully, mind-bogglingly slow.
The second problem is that it had no easy way of being accessed over a network link, last time I looked at it. So there's no chance of SSHing into a Windows box and administrating it from there, at least not without fiddling with a lot of hacks and workarounds I couldn't get to work.
The other place where unix shells have an advantage over Powershell is in there interface, as Powershell is currently quite basic in that department. There's limited tab completion and a prompt that can be altered (like PS1 under sh derivitives), but not much over that. Certainly nowhere near my personal favourite, Fish [wikipedia.org].
Re:At this rate... (Score:3, Informative)
http://geophile.com/osh/index.html [geophile.com]
http://dispatch.sourceforge.net/ [sourceforge.net]
Re:It's amazing people still use windows. (Score:3, Informative)
Actually, 3D acceleration in Linux is technologically ahead of Windows. What's behind is driver support, although that's coming around.
People use Windows because most people are not looking for the same things in an OS that you are.
Well, nobody in my family uses Windows anymore: they have all switched to either Mac OS or Ubuntu, both of which are considerably less hassle and overall cheaper.
Re:I'd love Powershell, if it weren't for one thin (Score:3, Informative)
So basically, what makes it suck less, is to use it more.
Re:It's amazing people still use windows. (Score:3, Informative)
$> diff --brief a/ b/
It just seemed worth pointing out.
Re:What is wrong with Cygwin? (Score:2, Informative)
A dedicated ReiserFS partition with a Slackware 11.0 disto and installation of coLinux on Windows solved (almost) all my problems. Bypass M$ entirely, the freedom of bash...
(The only snag is that cofs isn't finished yet)
As for powershell, I installed it when it was in beta and still called Monad, year or so ago, I was impressed, but it seemed like a lot of COM bloat to me... (FYI, I hate COM/OLE from a programmers perspective)
Re:At this rate... (Score:4, Informative)
The FOR command [microsoft.com] in the "legacy" Windows shell is pretty powerful, too. It even has horrible syntax, just like its UNIX fathers.
Yes, the legacy Windows shell sucks, but not as badly as most people assume. The NT shell can do a lot of stuff that most people don't even think to try. Great gobs of functionality have been added over the years, starting with Windows NT 3.5. And contrary to what many slashdotters think, the legacy shell on Windows NT-derived systems is not DOS, nor is it 16-bit. CMD.EXE is just another 32-bit or 64-bit process running on the NT kernel.
Re:At this rate... (Score:3, Informative)
I can offer a link to the download.microsoft.com page that pulls it for Vista. (all links are English x86, if you run English x64, you'll be able to navigate the download center by now).
Vista x86: http://www.microsoft.com/downloads/details.aspx?F
XP x86: http://www.microsoft.com/downloads/info.aspx?na=2
WS03 x86: http://www.microsoft.com/downloads/info.aspx?na=2
Get it, use it!
-- I worked briefly doing part of the steps of release management for this, so it's cool to see that people are enjoying it.
Re:What is wrong with Cygwin? (Score:3, Informative)
Re:It's amazing people still use windows. (Score:3, Informative)
% mkfifo
% mkfifo
% ls a >
% ls b >
% diff
That's just disgusting.
Yes that is disgusting. Fortunately, you're not the first person to notice this. Try this instead:
diff <(ls a) <(ls b)
There is a similar syntax for outputs as well. It's not perfect: you can't easily generate a general directed graph, but in that case, you would probably get deadlocks anyway, since programs tend to read files in order.
Re:Everyone should follow their lead... (Score:2, Informative)
another cool product is www.powergadgets.com for widget/gadget graphing on windows desktops...
Re:At this rate... (Score:1, Informative)
Re:Monad (Score:5, Informative)
Re:it's obvious THAT YOU ARE A LINUX TROLL (Score:3, Informative)
It amazes me just how little all the Windows advocates out there actually understand about the world of system administration and maintenance. They're so goddamn addicted to their little GUI tools, and yet they are so often forced to use substandard tools for automation. I'm not saying sh and its descendants are perfect, but compared to that worthless DOSesque piece of shit called CMD.EXE, they're like friggin' Einsteins compared to a low-level functioning mental retard.
I could give a shit about desktops, about whiz-bang GUI config settings. I find them so appalling inferior to a simple
Windows administration is an exercise in visual masturbation. It may take me a couple of hours longer to get Samba running, but management is infinitely easier. Follow a few basic rules about backing up conf files, and you can test things out, and if it doesn't work, just copy the backup conf file back, restart the Samba processes, and bang, all the evils you brought into the world just disappear. Windows and its advocates are based on the model that everything has to have fucking check boxes, radio buttons and drop down lists. I mean having to have a bloody script to control GUI apps is so symptomatic of the psychological disease your breed suffer from. Rather than learning how to function in an economical fashion, its all about finding reasons to justify the existence of a GUI on a server.
I won't debate that for Joe Q. Average, Windows is still at the top of the heap. But don't give me that shit about server environments, where the requirements are so different. I welcome the day when Microsoft gives me a command-line and simple scripting interface where I can modify any part of the system from a terminal session. But even giving us that won't answer horrors like the registry. How could you ever produce a CLI tool that could meaningfully control that. Guess what, on *nix boxes, it's as simple as vi, emacs, or even some Wordstar clone like joe if that's more you speed.