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$MyInvocation.Line
.
Import-Module -Scope
只能将范围缩小到Local
funfrom
”模块的模块示例:
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-Module .\myFavMods
-TestfunFromModuleA
Fun from module A.