Jamie Marshall
Jamie Marshall

Reputation: 2306

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.

Upvotes: 3

Views: 11446

Answers (1)

Sage Pourpre
Sage Pourpre

Reputation: 10333

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

Upvotes: 11

Related Questions