Writing Our First Script – Turning Simple Cmdlets into Reusable Code
Starting in this chapter, we’re going to look at how we can put the basic concepts we’ve learned together into scripts and tools that we can reuse, adapt, and distribute for others. In the coming chapters, we’re going to look at creating functions and script blocks, error handling and debugging, creating modules that allow us to distribute our code as tools, and finally, securing PowerShell. In this chapter, though, we’re going to start with the basics: turning a handful of cmdlets into a script.
We’ll start by discussing scripts in general and why we might want to write one. After that, we’ll take a quick look at where we can find PowerShell scripts online, and then we’ll cover how we can run scripts.
Once we understand how to use other people’s scripts, we’ll dive into writing our own. First, we’ll learn how to identify changing values...