简体   繁体   English

Powershell加载二进制模块

[英]Powershell Loading Binary Module

I have few powershell script which I am trying to put into module. 我几乎没有尝试将Powershell脚本放入模块中。 In the same module I also intend to load ac# dll for token generation. 在同一模块中,我还打算加载ac#dll以生成令牌。 DLL uses System.Management.Automation. DLL使用System.Management.Automation。

在此处输入图片说明

#content of asr.psm1
Import-Module ".\tokengenerator\PowershellTokenGenerator.dll"
Get-ChildItem $psscriptroot\*.ps1 -Recurse | ForEach-Object { . $_.FullName }

The folder tokengenerator includes dll to generate OAuth2.0 token. 文件夹tokengenerator包含用于生成OAuth2.0令牌的dll。 How can I load powershell module and C# cmdlet under the same module. 如何在同一模块下加载powershell模块和C#cmdlet。 However, when I am trying to load the module I get the below error. 但是,当我尝试加载模块时,出现以下错误。

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

Use: 采用:

Import-Module "$PSScriptRoot\tokengenerator\PowershellTokenGenerator.dll"

to ensure that the DLL is found relative to the script module's ( *.psm1 ) location, reflected in automatic variable $PSScriptRoot . 确保相对于脚本模块的*.psm1 )位置找到DLL,该DLL反映在自动变量$PSScriptRoot

By contrast, if you use Import-Module ".\\..." , the DLL is looked for relative to the current location ( . ), whatever it may be. 相反,如果使用Import-Module ".\\..." ,则相对于当前位置. )查找DLL,无论它是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM