When writing powershell modules (in powershell) how do I have commands run when the module is imported?
When the user runs import-module mymodule
I want the module to run some commands first to do some initial setup. how do I do this?
You can do the ScriptsToProcess
thing as mentioned, but you can also just put the code directly into the .psm1
file (outside of a function definition). It all gets executed when the module is imported, so there's no need to use a separate file. (Anything written to standard output while the on-import code is executing is generally discarded.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With