Introduction

Pre-Requisites

We’re assuming that you’ve already finished reading an entry-level tutorial like, Learn Windows PowerShell in a Month of Lunches, or that you’ve got some solid PowerShell experience already under your belt. Specifically, nothing on this list should scare you:

  • Find commands and learn to use them by reading help
  • Write very basic “batch file” style scripts
  • Use multiple commands together in the pipeline
  • Query WMI/CIM classes
  • Connect to remote computers by using Remoting
  • Manipulate command output to format it, export it, or convert it, using PowerShell commands to perform those tasks

If you’ve already done things like written functions in PowerShell, that’s marvelous - but, you may need to be open to un-learning some things. Some of PowerShell’s best practices and patterns aren’t immediately obvious, and especially if you know how to code in another language, it’s easy to go down a bad path in PowerShell. We’re going to teach you the right way to do things, but you need to be willing to re-do some of your past work if you’ve been following the Wrong Ways.

We also assume that you’ve read PowerShell Scripting in a Month of Lunches, a book we wrote for Manning. It provides the core narrative of “the right way to write PowerShell functions and tools,” this book essentially picks up where that one leaves off. Look for that book in late 2017 from Manning or your favorite bookseller. Part 1 of this book briefly slams through this “the right way” narrative just to make sure you’ve got it in your mind, but the Month of Lunches title digs into those ideas in detail.

Versioning

This book is primarily written against Windows PowerShell v5/v5.1 running on Microsoft Windows. In January 2018, Microsoft announced the General Availability of PowerShell Core 6.0, which is a distinct cross-platform “branch” of PowerShell. This branch has now become PowerShell 7, which was released in early 2020. As far as we can tell, everything we teach in this book applies to PowerShell 7, too - although some of our specific examples may still only work on Windows PowerShell, the concepts and techniques apply to PowerShell 7. However, PowerShell 7 includes some new scripting features which we’ll cover in a dedicated chapter or two.

The Journey

This book is laid out into seven parts:

  1. A quick overview of “the right way” to write functions.
  2. Professional-grade toolmaking, where you amp up your skills, comes next in a second narrative. This part is less tightly coupled than the first, so you can just read what you think you need, but we still recommend reading the chapters in order.
  3. Moving on from toolmaking for a moment, we’ll cover different kinds of controller scripts that can put your tools to use. Read these in whatever order you like.
  4. Data sources are often a frustrating point in PowerShell, and so this part is dedicated to those. Again, read whichever ones you think you need.
  5. More advanced topics complete the book, and again you can just read these as you encounter a need for them.
  6. A high-level introduction to using Pester in your toolmaking development.
  7. Scripting for the PowerShell 7 and cross-platform world.

Following Along

We’ve taken some pains to provide review Q&A at the end of most chapters, and to provide lab exercises (and example answers) at the end of many chapters. We strongly encourage you to follow along and complete those exercises - doing is a lot more effective than just reading. We’ve tried to design the labs so that they only need a Windows client computer - so you won’t need a complex, multi-machine lab setup. Of course, if you have more than one computer to play with, some of the labs can be more interesting since you can write tools that query multiple computers and so forth. But the code’s the same even if you’re just on a single Windows client, so you’ll be learning what you need to learn.

Providing Feedback

Finally, we hope that you’ll feel encouraged to give us feedback on this book. There’s a “Contact the Authors” form on this book’s page on Leanpub.com.