Module ScriptToProcess: Is it possible to load functions into module scope preemptively?
ScriptsToProcess
scripts are dot-sourced in the importer's scope, and unless that scope happens to be the global one,[1] your module won't see the definitions.
To dot-source helper scripts in the context of your module, place them in a subdirectory named, say, scripts
, then place the following code in your RootModule
.psm1
file:
Get-ChildItem $PSScriptRoot/scripts -Filter *.ps1 |
ForEach-Object { . $_.FullName }
Note that unless you expressly export functions defined in these scripts, they'll be visible inside the module only.
As for making enum
and class
definitions available to the importer:
Define them inside your module and make the importer import the module via using module
rather than via Import-Module
.
Only use a ScriptsToProcess
script to make enum
s and class
es available to the importer if you don't also use them inside the module too.
Note that if you tried to use the same script with both ScriptsToProcess
and module-internal dot-sourcing, you'd end up with enum
s and class
es that aren't the same in the two contexts - even though they appear to be.
[1] That is, when you run Import-Module
directly from the interactive Powershell prompt (or when you use an equivalent mechanism) - what matters is what scope the importer runs in. This is unrelated to what scope you load the module into, such as with Import-Module -Global