Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Must Powershell modules be placed in separate folders?

Using PowerShell 2.0

According to what I've read online, user-created powershell modules must each reside in their own directory. For example if I create a module called MyModule.psm1 it must reside in a folder called MyModule and reside in any directory listed in $env:PSModulePath.

If I have many modules for a project, it seems silly to me to have to create a separate folder for each one. Is this really necessary? Why? Any elegant way around it?

like image 599
Mark Allison Avatar asked Oct 16 '25 20:10

Mark Allison


2 Answers

If you want to just have the .psm1 file, you can import it by giving the path to the file itself rather than just the name of the module.

For example:

import-module c:\mymodules\folder\themodule.psm1

With this technique you can have as many modules as you want in the same folder. I don't know that I'd recommend this, but it does work.

like image 134
Mike Shepard Avatar answered Oct 18 '25 14:10

Mike Shepard


PowerShell modules can consist of more than one file, for instance for providing multi-language help or by splitting the functionality into several files. So yes, it's necessary.

like image 29
Ansgar Wiechers Avatar answered Oct 18 '25 12:10

Ansgar Wiechers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!