Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

powershell module startup commands

Tags:

powershell

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?

like image 780
red888 Avatar asked Jan 06 '23 04:01

red888


1 Answers

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.)

like image 67
briantist Avatar answered Jan 15 '23 09:01

briantist