powershell - 为嵌套的 PowerShell 模块创建 list

标签 powershell powershell-2.0

我对嵌套的 PowerShell 模块有一个小问题。
Get-Module正确识别 ExportedCommands ,但 ModuleType被列为 Script ,而不是 Manifest :

PS>get-module

ModuleType Name                      ExportedCommands
---------- ----                      ----------------
Script     Bar                       Get-Bar
Script     Foo                       Get-Foo

目录结构:
|-Modules
  |-Foobar
    |-Foobar.psd1
    |-Bar
      |-Bar.psm1
    |-Foo
      |-Foo.psm1

Foobar.psd1:
...
# Script module or binary module file associated with this manifest
ModuleToProcess = ''

# Modules to import as nested modules of the module specified in ModuleToProcess
NestedModules = 'Foo\Foo.psm1', 'Bar\Bar.psm1'
...

我是否正确构建了 PSD1 文件?在我的情况下,我是否需要一个虚拟/空的 Foobar.psm1 文件(在 PSD1 文件中有相应的条目)?我需要嵌套的目录结构,还是可以只在父目录 (Foobar) 中包含两个 PSM1 文件(bar.psm1 和 foo.psm1)?

最佳答案

目录结构需要是:

|-Modules
  |-Foobar
    |-Foobar.psd1
    |-Bar.psm1
    |-Foo.psm1

Foobar.psd1 需要:
...
# Modules to import as nested modules of the module specified in ModuleToProcess
NestedModules = 'Foo.psm1', 'Bar.psm1'
...

关于powershell - 为嵌套的 PowerShell 模块创建 list ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16424171/

相关文章:

PowerShell:将整个文本文件内容存储在变量中

c# - 远程调用时 Powershell SendKeys 访问被拒绝

powershell - 如何按上次修改日期顺序获取目录中的 N 个文件?

powershell - 在 Powershell 2.0 中清除公共(public) MSMQ 队列

sharepoint - Powershell 错误 "The term ' Get-SPWeb' 未被识别为 cmdlet、函数的名称...”

regex - 删除Powershell中的多个空白

powershell - Close-SMBOpenFile 抛出错误并且未在 try-catch 中捕获

azure - 使用 Azure CLI 注册应用程序后在 PowerShell 中创建管理员同意会出错

powershell - 使用EWS检查未读的交换邮件数

powershell - 重定向附加到同一日志文件的标准和错误输出