in powershell, can we have several .psm1 files for a module ?


I'm writing some powershell. In order to get things cleaner i decided to write my code in modules.
So far i always work the same way :

1. I create a folder inside C:\Program Files\WindowsPowerShell\Modules\
2. I create a file with the same name as the folder in inside.
3. I invoke the create manifest file command.
4. I reference the psm1 - file with code - in the psd1.

how can i add more psm1 files inside a module.

thank you in advance.

Erwin .
Erwin PombettAsked:
Who is Participating?
Guy LidbetterCommented:
Hi Toshi

I assume you mean how can you add more PSM1 (Modules) into a PSD1 (Manifest) ???

In that case you need nestedmodules to be specified in the manifest... i.e.
NestedModules =  @('database\Database.psm1', 'build\Build.psm1')

Open in new window

you can use PS1 files with functions as well...


Erwin PombettAuthor Commented:
Hello Guy Lidbetter,

thank you for your answer.

yes ! that's my necessity ;) i dont want to create a single psm1 per module and i was wondering if we could add more on the RootModule configuration variable but you answered to my question.

*** Question :
Do this means that by removing the module and importing it,  all code in files : the one referenced by the configuration variable Rootmodule and also those under Nested modules will be refresh ?

Thank you in advance for this last info.
Guy LidbetterCommented:
If you update ANY of the modules in the nest, or the manifest you would have to manually reload the module (PSD1) in order to use them.


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.