Chapter 21. Creating your own “cmdlets” and modules
At the end of chapter 19, you saw how to make a function (in listing 19.5) that output custom objects to the pipeline. Mastering that kind of output is a key to becoming a PowerShell guru, but there’s also the question of input.
In chapter 19, we passed input to the function by means of a parameter. In this chapter, we’re going to look at some other means of getting input into the function. By combining different input techniques with what you already know about producing output, you’ll find that you can create a tool that behaves almost exactly like a PowerShell cmdlet!
As I said, the function in listing 19.5 accepted input primarily through a parameter. In order to make a tool like that more useful, it would be nice if we could pass in multiple pieces of input (the function in listing 19.5 only worked with a single computer name, for example), and pass them in either using a parameter or from the pipeline. That would give us a fully reusable tool that looks and works much like a cmdlet. Ideally, we could even have the shell do some input validation for us, such as marking a parameter as mandatory and automatically prompting the user if it wasn’t provided.