Chapter 22. Improving your parameterized script

 

In the previous chapter, we left you with a pretty cool script that had been parameterized. The idea of a parameterized script is that someone else can run the script without having to worry about or mess with its contents. Script users provide input through a designated interface—parameters—and that’s all they can change. In this chapter, we’re going to take things a bit further.

22.1. Starting point

Just to make sure we’re on the same page, let’s agree to use listing 22.1 as a starting point. This script features comment-based help, two input parameters, and a command that uses those input parameters. We’ve made one minor change since the previous chapter: We changed the output to be selected objects, rather than a formatted table.

22.2. Getting PowerShell to do the hard work

22.3. Making parameters mandatory

22.4. Adding parameter aliases

22.5. Validating parameter input

22.6. Adding the warm and fuzzies with verbose output

22.7. Lab

22.8. Lab answer

sitemap