简体   繁体   English

从目录导入PowerShell脚本或模块

[英]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. 例如,如果我在“ somedirectory \\ here \\”中有五个模块,我希望一个内衬将它们全部导入。

How is this done in PowerShell? 如何在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). 另外,我已经知道用户配置文件($ profile)。 That will not work as a solution in this case. 在这种情况下,这不能作为解决方案。

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 仅加载模块(PSM1)文件

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

To load modules (PSM1) and scripts (PS1) 加载模块(PSM1)和脚本(PS1)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM