1. 6

I’m wondering because I haven’t ever used PowerShell, but I’ve heard that’s decent and worth looking into. I read somewhere that instead of piping around text, PowerShell pipes around objects, since Windows is more object/API-based vs UNIX which is text/file-based.

  1. 6

    There are two big differences, in my opinion, between PowerShell and Unix shells.

    The first difference you’ll hit is that PowerShell is object-based, not text-based. This is a good thing: PowerShell allows you to pass around richer objects (dates, actual numbers, and so on), rather than string representations of the same. This means you don’t have to remember some arcane combination of flags to get the data you need presented as text format, and also allows cleanly separating out presentation from data. Indeed, it’s pretty easy to whip up custom output tooling for the end of a long pipe chain (see Out-GridView for a built-in example), or even to feed them directly to .NET libraries.

    This is cool in itself, but it actually becomes most useful because it relates tightly to the second major difference. This isn’t PowerShell-specific as such—it’s really about Windows—but because it affects PowerShell’s usefulness and usage so much, I want to include it here: because Windows encourages you to administer multiple machines directly form your own machine via COM/RPC, and therefore exposes all of its internals as network-friendly objects, PowerShell makes working with large swaths of boxes in a structured way very easy. If you want to alter the configuration of a pile of machines, then instead of doing the equivalent of Unix (ssh into a bunch of boxes, rewrite a file, restart a service, log off), you can instead pull in those boxes configuration objects into your local PowerShell, inspect them, alter them, and commit your changes. This is where PowerShell’s focus on objects truly shines: it makes having almost Plan 9-like manipulation of a cluster pretty trivial.

    Beyond that, a shell is a REPL is a shell. Shells just have a specific class of operators and features that make them more common. At the end of the day, PowerShell is just a REPL for a .NET language with syntax that’s useful for scripting and some objects and methods to help with that. You can use PowerShell from any .NET language, and consume any .NET assembly from PowerShell.

    1. 4

      If you’re using Windows at all and you’re a developer, PowerShell is a great piece of your toolkit. In particular, if you work in .NET, there’s a lot of fast prototyping that can be done with PowerShell. I would say it’s more full fledged than most UNIX shells… I have seen very large systems written in it (>10k lines of code) to do large scale system administration (multiple servers, etc). That’s not to say those were nice systems to work with :).

      You are correct about piping objects around. PowerShell has a lot of nice innate features for object introspection since everything it passes around is a variant on a .NET object of some sort. PowerShell when used from the shell itself (as opposed to a script) tends to read as follows:

      (do a thing) | ForEach-Object { (do something with each returned object) } | Format-Table

      I was initially turned off by some of its wonky syntax, which it has plenty of, but it’s a good language to have in your toolkit and there’s a huge amount of data you can glean from a Windows system by working with it. I often wish UNIX-based OSes had something similar for collecting the sort of detailed info you can get out of PowerShell.

      1. 3

        PowerShell seems more complex, harder to get started with - more like a full-fledged programming language, perhaps. I haven’t used it enough to get to the good parts that I’m told are there.

        1. 3

          My issues with it initially were treating it like I treat UNIX-based shells. That is, as pretty simple glue code.

          The value of PowerShell shows up when you start using it to do OS introspection that’s naturally part of the language and/or .NET libraries.

          If you’re doing any significant work with Windows, which I spent most of my time in, then it’s absolutely worth adding to your toolkit.