PowerShell for Developers

PowerShell was written first and foremost for Windows system administrators, and the benefits to this community are clear. It’s not as clear what developers should make of PowerShell.

Administrators can learn PowerShell as a shell first, and gradually transition from interactive use to scripting. They may learn PowerShell as their first programming language and not even give too much thought to the language per se. But a developer has to ask why and when to use PowerShell rather than another language, such as C#.

Doug Finke’s new book Windows PowerShell for Developers is “for developers” in a couple ways. First, the style of the book is geared toward developers. The book is small, less than 200 pages, because the author assumes the readers are experienced Windows developers who want to focus on what PowerShell adds to what they already know. Second, the book focuses on tasks a developer might want to do. Rather than show you how to create a new Active Directory user, as many PowerShell books would, this book covers topics such as

  • code generation
  • static analysis
  • interfacing with C#
  • embedding PowerShell in your application
  • working with XML and JSON
  • interfacing with Excel
  • creating DSLs.

So why should software developers use PowerShell? And what tasks should they do in PowerShell? One answer to the first question, implicit in the book’s examples, is that PowerShell makes it possible to carry out common tasks with little code. Another answer explicitly given in the book is integration.

Given PowerShell’s growing integration with the rest of the Windows platform, as PowerShell grows, so does your application.”

The book is full of examples of what tasks a developer might want to do in PowerShell. The examples I found most interesting were embedding PowerShell to provide a scripting language for your application and creating DSLs in PowerShell.

One pattern in the examples is text munging, whether that text is source code or common data file formats. Another pattern is integration, especially integrating Microsoft technologies. PowerShell is designed to make it possible to solve these kinds of problems with a minimum of ceremony.

I’ll close with a couple reasons why might a developer not want to use PowerShell in my opinion. The first is frequency of use. Although PowerShell can solve many problems with significantly less code than C# would require, you have to learn PowerShell first, and you have to use it frequently enough to remember it. You have to use PowerShell enough to repay the time invested in learning and practicing it.

The second reason is size. The C# language and the Visual Studio IDE were designed for large projects, but scale down fairly well for smaller projects. PowerShell was designed for the command line, but scales fairly well for large scripts. If you use PowerShell and C#, you’ll have to decide at what size you want to switch from one language to the other.

Related posts:

DSLs in PowerShell
Scripting and the last mile problem

Tagged with: ,
Posted in PowerShell
3 comments on “PowerShell for Developers
  1. Richard says:

    I hope your interest in PowerShell as an internal scripting language is limited to the point that it is “PowerShell” that could be embedded. Having powerful shell languages available as an embedded script language is as old as Tcl (1987), perl, python, etc.

    It’s a great way to enable system configuration management, or as we pronounce it now, “inversion of control”.

  2. Chris Nahr says:

    PowerShell is an interesting example for the very different approaches taken by shells and ordinary programming languages like C#, even when they obtain most of their functionality from the same library (.NET in this case).

    There’s no doubt that PowerShell is indeed very powerful and well-designed, and the introductory book I read (Windows PowerShell in Action, by co-designer Bruce Payette) was quite excellent. But coming from a Pascal/C background, I could never get used to the myriad specialized abbreviations. I still find it faster to just bang out a longer C# program than to look up exactly which magic incantations would make PowerShell do the same job in three lines.

  3. sahal says:

    Thanks for the nice review, I am an ITPro and just started reading this book