PowerShell自定义模块清单不公开声明的函数
我已经创建了一个PowerShell模块。该模块公开了3个函数。当我在没有清单的情况下直接安装它时,输出将是:PowerShell自定义模块清单不公开声明的函数,powershell,Powershell,我已经创建了一个PowerShell模块。该模块公开了3个函数。当我在没有清单的情况下直接安装它时,输出将是: > Import-Module AzureDD > Get-Module | Where { $_.Name -eq 'AzureDD' } ModuleType Version Name ExportedCommands ---------- ------- ----
> Import-Module AzureDD
> Get-Module | Where { $_.Name -eq 'AzureDD' }
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 0.0 AzureDD {New-AzureDDAppPermission, New-AzureDDAppRegistration, Sync-AzureDDStorageContainer}
这是因为我在psm文件中的最后一行是:
Export-ModuleMember -Function New-AzureDDAppRegistration, New-AzureDDAppPermission, Sync-AzureDDStorageContainer
现在我想添加版本和更多元数据,并继续
> New-ModuleManifest -Path .\AzureDD.psd1 -ModuleVersion "2.0"
这将创建一个新文件AzuerDD.psd1
。在这里我编辑了很多东西。除其他更改外,我还定义了导出函数,如下所示:
FunctionsToExport = @('New-AzureDDAppPermission', 'New-AzureDDAppRegistration', 'Sync-AzStorageContainer')
我可以成功地测试它:
> Test-ModuleManifest .\AzureDD.psd1
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 2.0 AzureDD {New-AzureDDAppPermission, New-AzureDDAppRegistration, Sync-AzStorageContainer}
但当我实际导入此命令时,它不会显示任何导出的命令:
> Import-Module .\AzureDD.psd1
> Get-Module | Where { $_.Name -eq 'AzureDD' }
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 2.0 AzureDD
看看与我的第一个代码片段相比,它是如何变成
Manifest
!我已经确保在重新导入模块之前,我一直都在删除模块AzureDD-Force
。函数导出
就像一个筛子-它只允许嵌套模块通过清单导出其函数,但它们仍然必须在某个地方定义
确保将脚本模块(.psm1
文件)指定为清单中的RootModule
(或至少是NestedModule
):
@{
# Script module or binary module file associated with this manifest.
RootModule = 'AzureDD.psm1'
# ...
}
您是否将现有的
psm1
指定为清单中的RootModule
FunctionsToExport
就像一个筛子——它只允许嵌套模块导出它们的函数,但它们仍然必须在什么地方定义!你搞定了。我确实指定了它,但我监督它在默认情况下被注释掉:-(。请回答我的问题,以便我可以确认它。