Chapter 7. Advanced functions and scripts
This chapter covers
- PowerShell scripts
- Writing advanced functions and scripts
- Dynamic parameters
- Default parameters
- Documenting functions and scripts
And now for something completely different . . .
Monty Python
In chapter 6 we introduced the basic elements needed for programming in PowerShell when we looked at PowerShell functions. In this chapter, we’re going to expand your repertoire by introducing PowerShell scripts.
Note
If you skipped chapter 6, you should probably go back and read it before proceeding. Why? Because all the material we covered on functions also applies to scripts.
Once we’re finished with the basics of scripts (which won’t take long), we’ll move on to PowerShell’s advanced production scripting features, which enable you to write full-featured applications complete with proper documentation. By the end of this chapter, you should be well on your way to becoming an expert PowerShell programmer.
Let’s dig into scripts to see what they have in common with functions and what additional features you need to be aware of. We’ll begin by looking at the execution policy that controls what scripts can be run. Then you’ll see how parameters and the exit statement work in scripts. We’ll also spend time on the additional scoping rules that scripts introduce. Finally, you’ll learn ways you can apply and manage the scripts you write.