6 The many forms of scripting (and which to choose)

 

You probably think you’re the victim of bait-and-switch tactics by Manning. We use words such as tool and toolmaking but haven’t talked much about scripting. After all, the title of this book is Learn PowerShell Scripting in a Month of Lunches. But what if I told you that scripting equals toolmaking in this instance? Scripting is a pretty generic word, and in the PowerShell universe, we feel that it can refer to a couple of specific and valuable things that we’ll go over in this chapter.

6.1 Tools vs. controllers

Think about a hammer. A hammer is a tool, and it’s probably one you’ve at least seen before, even if you’ve never wielded one. A hammer is self-contained; it’s main purpose is to strike other things. A hammer has no context about its life and no clue about its destiny. A hammer may be used one day to help build a house, another day to break a window, and another day to smash your thumb. Sitting alone in a toolbox, a hammer is useless unless someone is swinging it.

You’re the one that is going to swing the hammer to strike the nail (or your thumb). Think of the hammer for a second again. You must think about how hard you’ll swing it and what you’ll hit (be it a nail, window, or thumb). The desired output is to hit the nail and drive it into the wood, producing an audible ping as the nail head is struck. But what happens if you hit the nail at an angle? It will bend or break, having unintended consequences.

6.2 Thinking about tools

6.3 Thinking about controllers

6.4 Comparing tools and controllers

6.5 Some concrete examples

6.5.1 Emailing users whose passwords are about to expire

6.5.2 Provisioning new users

6.5.3 Setting file permissions

6.5.4 Helping the help desk

6.6 Control more

6.7 Lab

Summary