I am working on a PowerShell script for generating reports, I am loading and calling modules provided by the end user.
First I call a user provided setup function, then load the modules:
# Load user provided modules
($userModules = Get-ChildItem ($userModHome + "*.psm1")) | ForEach-Object { Import-Module (join-path $userModHome $_.Name) } | Out-Null
After calling setup and loading, I loop through the list of modules and call each one. This is all straight forward, but what I would like to accomplish is not requiring global variables for everything that a function would need.
I could require the setup function return an object that contains everything that any function may need, and then pass that data structure in to each module, but that is possibly passing a lot of extra stuff.
I am wondering if there is someway to determine at run-time what to pass to a module, or some other elegant solution to dynamically load and execute modules without using global variables.
In a nutshell I think I am asking if Powershell has reflection to can be used to determine the details of a module and then call. The difficult part I assume is determining what parameters to pass a specific module.