相关疑难解决方法(0)

Powershell模块设计 - Export-ModuleMember

我正在构建一个模块,用于导出我想通过我的个人资料提供的cmdlet.此cmdlet的实现分布在多个实现文件中,这些文件包含我不想公开的实现函数.所以我使用Export-ModuleMember来隐藏它们.

get_something.psm1

import-module .\get_something_impl.psm1

function Get-Something {
    [cmdletbinding()]
    Get-SomethingImplementation
}

Export-ModuleMember -Function Get-Something
Run Code Online (Sandbox Code Playgroud)

然后我将get_something.psm1添加到我的个人资料中.通过仅导出Get-Something,我的所有实现功能都保持"私有".

我遇到的问题是,当使用Export-ModuleMember命令时,每次我需要一个函数时,我必须在我的实现文件中导入一个模块.例如,假设我有一个模块person.psm1,其中包含我需要在所有实现文件中调用的函数Get-Person.现在我必须在每个需要调用Get-Person的文件中导入person.psm1.这是使用Export-ModuleMember -Function Get-Something的结果.没有它,我只需要导入person.psm1一次,它就可用了.

实质上,Export-ModuleMember不仅阻止我的实现到外部,它还阻止了我自己的实现.

这是预期的,并被认为是设计Powershell模块的正常方面吗?

powershell function powershell-module

7
推荐指数
1
解决办法
6511
查看次数

标签 统计

function ×1

powershell ×1

powershell-module ×1