Chapter 7. Advanced functions, part 1
PowerShell has a number of types of functions: basic functions that just return a value, filtering functions that work in the pipeline, and so on. We’re going to jump straight to the top of the food chain and build an advanced function—what some people call a script cmdlet. Frankly, we think this is where you should be aiming for any tool you build—even if it’s just a tool for your own personal use. Advanced functions do a lot of heavy lifting for you, giving you a great deal of functionality essentially for free. You can end up with the equivalent of a cmdlet without having to program in Visual Studio.
If you have any programming background, this will require you to reach into your mind, locate whatever you already know about functions, and delete that information—or at least willfully forget it for a while. PowerShell functions are a different beast, especially if you’re building them to truly leverage PowerShell’s functionality. Stick with us through the chapters in this part of the book, because one step at a time we’re going to show you how to build something truly awesome.
At the end of the day, advanced functions all end up looking remarkably similar, so we tend to start with a template of one. It’s in the following listing, and it’s a good starting point any time you need to build a tool to do anything at all.