【发布时间】:2019-09-08 07:31:43
【问题描述】:
我尝试将几个 powershell 脚本放入模块中。在同一个模块中,我还打算加载一个 c# dll 来生成令牌。 DLL 使用 System.Management.Automation。
#content of asr.psm1
Import-Module ".\tokengenerator\PowershellTokenGenerator.dll"
Get-ChildItem $psscriptroot\*.ps1 -Recurse | ForEach-Object { . $_.FullName }
tokengenerator 文件夹包含用于生成 OAuth2.0 令牌的 dll。如何在同一模块下加载 powershell 模块和 C# cmdlet。但是,当我尝试加载模块时,出现以下错误。
Import-Module D:\repo\src\aadsr\setup\asr.psm1
Import-Module : The specified module '.\tokengenerator\PowershellTokenGenerator.dll' was not loaded because no valid module file was found in any module directory. At D:\repo\src\aadsr\setup\asr.psm1:1 char:1
+ Import-Module ".\tokengenerator\PowershellTokenGenerator.dll"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (.\tokengenerato...enGenerator.dll:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
【问题讨论】:
-
PowershellTokenGenerator.dll是 PowerShell 模块吗?Import-Module仅用于导入 PowerShell 模块,不适用于任何旧的 C# 库。看看Add-Type。 -
dll是二进制powershell模块
-
它是否在您的模块之外加载?即,如果您打开控制台并直接在文件上使用
Import-Module,它可以工作吗?此外,DLL 是否编译为与您正在运行的 PowerShell 版本相同的操作系统类型(例如 64 位)
标签: powershell