我已经将模块"ModuleFoo.psm1"导入到我的脚本中:"ModuleBar.ps1"
我调用导入模块中的方法,该方法执行点源以函数 BarFunction.ps1:
function Dot-SourceBarFunction()
{
. "BarFunction.ps1"
}
我是否可以使此 BarFunction.ps1 可从父范围访问:ModuleBar.ps1?
这应该只是工作,例如:
-- Outer.ps1 --
Import-Module $PSScriptRootmodule.psm1
Get-Foo
-- Module.psm1 --
. $PSScriptRootinner.ps1
-- Inner.ps1 --
function Get-Foo {
"$($MyInvocation.MyCommand.Name) called"
}
这将输出Get-Foo called
. 函数默认在模块中公开可见,因此当您对在模块中提取函数的脚本进行点源时,这些函数会自动公开。