Chapter 6. The many forms of scripting (and which to use)

 

We’ve used the words tool and toolmaking a lot so far in this book, and we’re almost ready to start building tools. But we need to acknowledge that the title of this book uses the word scripting, and that wasn’t meant as a bait and switch. You see, for us, scripting is a pretty generic word, and in the PowerShell universe we feel that it can refer to a couple of distinct and valuable things.

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 a self-contained thing; it basically only does one thing: 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. A hammer, sitting alone in a toolbox, is essentially useless. It takes up space and doesn’t do anything.

You, in this analogy, are a controller. You give the hammer meaning and a purpose. You give it context. You decide if it will strike a nail or someone’s head. You give the hammer input—how hard it’s being swung, what it’s being swung at, and so on. You take the hammer’s output, like how loud a noise it makes, and you do something with that output, like decide to go buy some earplugs.

6.2. Thinking about tools

6.3. Thinking about controllers

6.4. Comparing tools and controllers

6.5. Some concrete examples

6.6. Control more

6.7. Your turn