ModuleForge

Testing how we get validators, enums and Classes to work Consistently

Notes on Scope

When you want to use Classes, Enums and custom Validator extensions in your PowerShell module, you need to be aware of the scoping concerns and problems that such objects bring. Essentially

To stop too much repeating, we will just refer to all classes, enums and validators as special snowflakes

Notes on Nested Modules

Nested Modules refers to when you make a new module manifest, you can provide an array of PS1/PSM1 files that live in the same folder as the Manifest (PSD1) and Root Module (PSM1) file, and when importing the module, these get run first. It looks like this New-ModuleManifest -NestedModules @('script1','script2')

This could be used, in theory, to make sure our special snowflakes load in the right order. Here’s my notes on testing this out

Notes on ScriptsToProcess

Similar to Nested Modules, you can supply New-ModuleManifest -ScriptsToProcess @('script1','script2'), and PowerShell will effectively dot-source all of these just prior to importing the module. This has advantages over nestedModules because all the scripts get processed on the session scope, making them inherently available in the module scope, but its not clean either:

A note on DSC Resources

Just some special notes on previous testing (Circa 2018) external files with DSC Resource modules. DSC modules seem to change just about everything above

So whats the best approach? Testing notes