PowerShell:导入模块,但没有“ExportedCommands"可用的 [英] PowerShell: Import-Module, but no "ExportedCommands" available

查看:50
本文介绍了PowerShell:导入模块,但没有“ExportedCommands"可用的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用

Import-Module -Name <path_to_local_dll> -Verbose

DLL 文件中包含的 cmdlet 不会导出.

the cmdlets contained in the DLL file are not exported.

因此,当我输入 Get-Module 时,会列出我导入的模块,但没有任何 ExportedCommands.为什么?

Thus, when I type Get-Module my imported module is listed, but without any ExportedCommands. Why?

ModuleType Name                      ExportedCommands
---------- ----                      ----------------
Binary     MyModule

在具有相同软件(PowerShell、.NET Framework 等)的第二台 PC 上,相同的导入 DLL 文件工作正常.在那里我得到了 ExportedCommands.

On a second PC with the same software (PowerShell, .NET Framework, ...), the same imported DLL file works fine. There I get ExportedCommands.

这种行为取决于什么?

不幸的是,Import-Module cmdlet 没有表明它无法导入 cmdlet.有没有办法知道它失败的原因?

Unfortunately, the Import-Module cmdlet gives no indication that it failed to import the cmdlets. Is there a way to get an indication why it fails?

推荐答案

两件事:

  1. 确保您使用的是模块清单文件(.psd1 文件).更多信息可以在如何写作中找到一个模块清单

最重要的是,编辑您的清单文件并确保它引用您的根模块,如下所示:

Most importantly, edit your manifest file and make sure it references your root module as follows:

RootModule = '你的模块名称'

RootModule = 'name of your module'

我刚刚完成了几个小时的战斗,我无法弄清楚我的其他模块缺少什么.这确实成功了!

I just finished fighting with this for a few hours and I couldn't figure out what I was missing from my other modules. This did the trick for sure!

这篇关于PowerShell:导入模块,但没有“ExportedCommands"可用的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆