Chapter 16. Filling out a manifest

 

Up to this point, you’ve been relying on a little PowerShell magic to make your commands—which are contained within a module—run. It’s worth digging into this magic a bit, because there’s a ton more you can do with it.

16.1. Module execution order

When PowerShell goes looking for modules, it first enumerates all the folders listed in the PSModulePath environment variable. Each folder under each of those paths is considered to be a potential module.

Within a module folder, PowerShell looks for the following:

  1. A .psd1 file having the same filename as the module’s folder name. This is a module manifest and tells the shell what else needs to be loaded.
  2. A .dll file having the same filename as the module’s folder name. This is a compiled or binary module, usually written in C#.
  3. A .psm1 file having the same filename as the module’s folder name. This is a script module.

You’ve been using number 3 on that list. If you create a file named \Documents\ WindowsPowerShell\Modules\Fred\Fred.psm1, then you’ve created a script module named “Fred,” and whatever functions are in that .psm1 file will become commands that PowerShell can run. This is a super quick and easy way to get a module up and running, but it has some disadvantages.

16.2. Creating a new manifest

16.3. Examining the manifest

16.4. Your turn