Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import PowerShell scripts or modules from a directory

I want to import a bunch of modules at once for various scripts based on directory. For instance, if I have five modules in 'somedirectory\here\' I want a one liner to import them all.

How is this done in PowerShell? Is there something like a manifest I can make with names of all the modules in it that will help me import them all?

Also, I'm already aware of user profiles ($profile). That will not work as a solution in this case.

like image 627
Jamie Marshall Avatar asked May 06 '26 15:05

Jamie Marshall


1 Answers

Well, add this one liner to the beginning of a script, change the path to where you desire the files to be loaded and all is set.

To load the module (PSM1) files only

'G:\sync\Office\*.psm1' | gci | Import-Module 

To load modules (PSM1) and scripts (PS1)

'G:\sync\Office\*' | gci -include '*.psm1','*.ps1' | Import-Module
like image 122
Sage Pourpre Avatar answered May 09 '26 16:05

Sage Pourpre



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!