Chapter 25. Script modules and manifest modules

 

This chapter covers

  • Turning a PowerShell script into a module
  • Exporting module members
  • Using a module manifest
  • Working with dynamic modules

In previous chapters, we’ve shown you how to build a script—or, more likely, a function—that works much like a native PowerShell cmdlet. In this chapter, we’re going to show you how to package multiple functions together into a distributable form that can be loaded into, and unloaded from, the shell. You’ve almost certainly used these modules before, perhaps loading the ActiveDirectory module. The only difference in what you’ll build now is that you’ll work entirely in PowerShell’s scripting language, whereas many of the modules you’ve used to this point will have been written in Visual Studio.

Note

We covered modules more extensively in chapter 5. If you need a refresher on how to load or unload modules, please refer back to that chapter.

25.1. Making a script module

Listing 25.1 shows a complete script that contains a single function. This is a repeat of a function that you built in an earlier chapter; you’ll use it as a starting point. Remember that you can easily add as many functions to this script as you want to—we’re sticking with a single function to keep things easy to read.

25.2. Exporting module members

25.3. Making a module manifest

25.4. Creating dynamic modules

25.5. Summary