Learn PowerShell as a shell first

When I was learning PowerShell, I thought of it as a scripting language that has a shell. But the right way to think of it may be the opposite, a shell that has a scripting language. Apparently others have followed this same change of perspective.

Don Jones and Jeffrey Hicks open their new book Learn Windows PowerShell 3 in a Month of Lunches by explaining that they first saw PowerShell as a VBScript replacement and taught it that way.

Since late 2009, however, a shift has occurred. More and more administrators who don’t have prior VBScript experience have started trying to learn the shell. All of a sudden, our old teaching patterns didn’t work very well, because we focused on scripting and programming. That’s when we realized that PowerShell isn’t really a scripting language. It’s really a command-line shell where you run command-line utilities. Like all good shells, it has scripting capabilities, but you don’t have to use them, and you certainly don’t have to start with them.

[Don Jones wrote the first edition of the book, which I haven’t read. This quote comes from the second edition, coauthored with Jeffrey Hicks.]

Other PowerShell books I’ve read felt more like a programming language book than a book on a shell, more like, for example, The C Programming Language than The Linux Command Line. The latter seems to be a better analog for the new PowerShell 3 book: emphasis on interactive use first, programming second. At least that’s my first impression. The book isn’t finished yet—it’s part of Manning’s Early Release program—and I haven’t yet read all of the part that has been released.

If you’d like a chance to win a copy of Learn Windows PowerShell 3 in a Month of Lunches, please leave a comment below. I’ll draw a winner and the publisher will send you a copy of the book.

Update: I’ll draw a winner on Friday, June 29. Comments need to be posted by midnight Thursday in my time zone.

Related links

156 thoughts on “Learn PowerShell as a shell first

  1. I just started trying to run R scripts with powershell this week. I’d love to win a copy.

  2. I’ve been meaning to explore PowerShell so that I can finally shed the limitations of cmd.exe. Whenever I find myself developing under Windows, I invariably need a command prompt and some script or other, and cmd has been the lowest common denominator, but it lacks in power. If PowerShell is installed by default on new machines, then I definitely need to consider moving to it.

  3. I think PowerShell can be quite powerfull – especially if we one can combine it with .NET framework.

  4. I really like powershell, except that the terminal emulator really sucks. You don’t even get persistent history using the up arrow key.

  5. I’ve been wanting to learn PowerShell for a while now, but it never made sense to me. This book sounds like a great place to start. Thanks for the recommendation.

  6. I find PowerShell amazing. In the last six months I have gone from knowing nothing about it to writing scripts that automate my sql agent job monitoring, disk space reporting, quick and easy account removals from 700 plus databases across 4 domains all whilst becoming a sql dba and found time to write with the server team a GUI based tool to set RBAC for different types of New server builds creating all service accounts.

    All this with no previous scripting or programming knowledge.

    PowerShell is fantastically easy to learn. I find it very intuitive.

    A book would be fabulous to continue my development in my third career!

  7. I am happy microsoft finally got around to creating something like powershell. I am always looking for new tips.

  8. I’ve really started to use Powershell lately and love it, except for one thing: the console. The whole situation is just annoying: Powershell ISE is somewhat nice with intellisense etc and would in principle do the job, but for some weird reason they decided that it won’t support interactive legacy command line tools. I use git a lot, and so all of the interactive commands of git don’t work in PS ISE… I’ve also daddled with various alternatives (ConEmu, Console2), but none are really great, and I wish that MS would just provide a killer console out of the box to go along with their killer shell/language.

    The somewhat depressing thing is that we’ll probably have to wait until the next version of Windows for any progress, given that Powershell release cycles seem to be bound to Windows release cycles.

  9. Interesting. A year ago I had a small contract to write some back office scripts. I used VbScript since it would do what the client wanted (though those requirements changed almost weekly and were never finalized, a case study in “real world ” programming ). I considered PS at the time, but the excel/access documentation seemed lacking.

  10. I would love to have a copy of the book; having to spend a lot of time in DOS scripts; I have been seeking a resource to help me grasp power shell quickly and port my scripts over to powershell and take advantage of the newer features.

    Thank you John for the opportunity

  11. But the right way to think of it may be the opposite, a shell that has a scripting language.

    Well .. hunh. That’s probably how most of us learned DOS and batch programming, back when.

    I’ve been delaying learning PSH because … I do unix admin. Mostly. And it compares badly to, say, Bash or ZSH.

    And dos batch files have been good enough, dadgum it. I _know_ dos batch, and there are deadlines, the time cost of Learning Yet More New Stuff was not worth it.

    Next time I have a need to login to a windows host, I’ll try real hard to think of it as a shell, not a language.

  12. There are things I prefer about bash, especially ways of reusing commands you’ve typed before. Maybe there are PowerShell counterparts that haven’t learned about. But the big advantage of PowerShell is piping objects rather than text.

  13. But the big advantage of PowerShell is piping objects rather than text.

    Oh, I get that part of it.

    What I need is to be given – or to give myself – a task that _must_ be done and _must_ be done in PowerShell.

    Nothing says ‘learn this’ like an unspoken ‘your reputation / job are on the line if you don’t’.

  14. “But the big advantage of PowerShell is piping objects rather than text.”
    I’m very curious about this statement – it is a direct refutation of the Unix approach, and I’m curious what it gets you. When I first heard that’s what they were doing, I was baffled as to why. What is the benefit of piping opaque binary objects? I must be missing something.
    Please include my name in the drawing, I’m also curious about PowerShell. I use cygwin at work, but maybe PowerShell would be more useful than I give it credit for.

  15. Thanks for the link. I ‘ve just read it twice. I am also a little leery of magic; it’s great when it works, but it will always fail at some point and make things much more difficult. Maybe there is a net benefit, I don’t know yet.
    The benefit of text as universal interface is its transparency. Yes, there are sometimes grubby text munging steps in-between the “real” commands, but in practice, I rarely introduce bugs there. This is because I iteratively build up the pipeline by hitting up arrow to get the previous command, and then modifying it to fix it or add to it.
    To clarify: I’m skeptical about PowerShell, but it’s entirely possible its magic is a net win. It seems I should spend some more time researching it.

  16. Dave Cottlehuber

    I’m interested in this book – I write erlang programs and maintain CouchDB for Windows. Currently its all built with a hideous mix of cygwin and cmd files wrapped around 4 different compilersrunning under cygwin bash. Maybe psh would make the difference!

  17. I am a big Linux user and like bash a lot. But then at work, my primary and only OS is Windows. So, have no other option other than using Cmd. Looking at the limitations of Cmd, I was always thinking of learning PowerShell to augment my work and be more productive and efficient. Probably this book might be the right motivation for this.

    All the best John.

  18. I agree that PowerShell should be learned as a shell first. I’ve found that most of the “scripts” that I write are actually functions that I then use at the PS prompt. Writing functions instead of complete scripts lets me create another layer of abstraction so I can get quite a bit done by placing a few functions together in a pipeline.

    John: One way of using previous PS commands is to use ‘#’ followed by part of a command from your history then [tab] to complete. for example:

    PS>gps| #[part of command A][tab]| #[part of command B][tab]

    I’m not that familiar with bash so I’m not sure how close this comes to bash’s command reuse.

  19. I really enjoyed Don’s sessions at TechEd. I would love to get a copy of his book.

  20. I’m still trying to learn PowerShell and get stuck from time to time. This book would be useful as another source for learning.

  21. I missed out on attending TechEd, this would be a GREAT opportunity for me to get caught up on PowerShell 3. I really enjoy all your posts and teachings. Thanks!!!

  22. Powershell has become part of my everyday life.. I need to get a copy of this book!

  23. I have almost completed my rewrite of all my batch scripts to Powershell v2 and I know I will need to clean them up with V3.

  24. Doh !!!

    Still having lunch with “Powershell 2.0 Month of Lunches”. Do you think it would be rude to get up and walk out in favor of a her hotter new sister?

    Even if you don’t win the psh 3.0 book. I’ll probably pick up the tab for lunch again ;)

    -Rich

  25. Matthew, the nice thing about objects vs. text is that the .NET objects in windows have a large amount of information contained in them that are difficult to get to via text utilities, already in a variable type that is immediately useful. A simple example. File dates provided by dir as simple text in a command shell. Unless you have a special utility, trying to do any date math is non-trivial task. With powershell, the last access time is a property of the file object, and is already typed as a datetime object itself. So to find, say, all files that have not been accessed in the last 30 days is amazingly simple in powershell. In addition, the fileobject has methods built in, so doing things like copying or moving files is directly available once you have the file object in the pipeline.

    and if you still have utilities that provide text output you need to use, you can simply assign them to a variable like this:

    $a=ipconfig.exe

    and $a is now an array with all the text output that you can parse to your hearts delight.

    Finally, your method of building up commands using previous commands is exactly what i do in powershell. Admitedly, it’s probably not as simple as commands that emit text directly, but it still works, and powershell gives you the tools to inspect the objects as you need to.

  26. I would agree that I first saw powershell as a vbscript replacement. After reading the Powershell 2.0 Month of Lunches, I can’t wait to see what the updated version would be like. I am now working through the Scripting and Toolmaking book. It is fun to learn.

    -Chris

  27. I like the idea of powershell, but I already know a bit of bash, and have Cygwin installed; What is the incentive for a very casual user to relearn everything, rather then just use bash or zsh?

  28. Canageek, if you will be administering windows systems, learning powershell will be very important. Microsoft is making powerhshell central to their management strategy.

    Oh, and I would welcome the book as well!!

  29. This sounds like a good book. I’ve been wanting to learn more about PowerShell and I don’t have a lot of programming experience. I’ll have to check it out.

  30. Mark,
    The idea of date-manipulation functions is a good example. The case of simply finding them based on modification time is actually pretty easy with unix’s ‘find -mtime’, but I still see your point about having more rich semantic support for certain types of operations. For all of us who WON’T win the book – does anybody have any websites they can recommend for learning PowerShell?

  31. Me! Me! Pick me! I love the command line, but I’ve wrung about as much out of CMD.exe as I can. I’ve never been able to get Cygwin to play well with my machines. PowerShell seems to be intended in the same vein, but more “naturally” integrated with Windows.

  32. I feel, as a 100% windows-based developer, I should know more about PowerShell then the limited amount of twiddling I have done so far. I’d love to receive this book.

  33. @Mark: More like, I have two lists of numbers and need them in one file. Or I need to multiply every number in this file by a coefficient. Or extract data from the output of a spectrometer or such. Generate a series of input files for a software package then run all of them.

  34. Rajesh Attaluri

    Powershell become necessary skill. powershell admin most of the Microsoft products and the products list is growing.In my opinion its the time to start learning powershell if anyone not started yet. Anyone can start learning powershell with known commands like dir,md then gradually can learn the other commands.
    Don Jones is well known trainer on powershell and to follow his teaching approach no scripting or programming knowledge required.
    I believe “Learn Windows PowerShell 3 in a Month of Lunches” would be the best resource to start learning powershell and would recommend this book(and the previous book Learn Windows PowerShell in a Month of Lunches) to any administrator.

  35. Interested to see how far PowerShell can go toward replacing the need for tools such as Cygwin or GoW.

  36. Schnitzelspecht

    I’d like to have a copy of this book. All books about Powershell I’ve seen so far are like programming books like you stated. I’d love to see how this book teaches me Powershell.

  37. I’ve just started tinkering with PowerShell and the book sounds like exactly what I need.

Comments are closed.