如何在powershell中进行`import-module'到父级会话/process?

问题描述 投票:0回答:1

I在A

myFavMods.ps1
中进口我最喜欢的模块:

Import-Module a
Import-Module b
...

这样运行时,我的会话中没有模块:

> ./myFavMods.ps1
> funFromModuleA
funFromModuleA: The term 'funFromModuleA' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

使用

.
操作员运行它时,它可以工作:

> . ./myFavMods.ps1
> funFromModuleA
Hurray this is funFromModuleA reporting!

无论我如何执行脚本如何,都可以使用

funFromModuleA
? 有可能
Import-Module -Scope 'GlobalGlobalAllTheWayUp'
吗?

到目前为止我知道的 Profile

我知道PowerShell配置文件,但我只想明确导入我最喜欢的模块。

制作脚本检查如何执行脚本

i我可以使用

$MyInvocation.Line

检查脚本是否正在使用a

.

调用,但我宁愿让它起作用,无论调用方式如何。

Import-Module -Scope
只能将范围缩小到

Local

	

为此,您可能会考虑创建一个包括您所有“

funfrom

”模块的模块示例

powershell
1个回答
0
投票

function funFromModuleA { 'Fun from module A.'} Export-ModuleMember -Function funFromModuleA 。\ myfavmods.psm1 function funFromModuleB { 'Fun from module B.'} Export-ModuleMember -Function funFromModuleB

新清单

New-ModuleManifest .\myFavMods\myFavMods.psd1  -NestedModules '.\a.psm1', '.\b.psm1'

Import模块

Import-Module .\myFavMods
 -Test

funFromModuleA Fun from module A.
    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.