powershell - 导入模块组装错误

标签 powershell import-module

我正在尝试编写 PowerShell,但失败得很惨。

Set-ExecutionPolicy Unrestricted
Import-Module -Assembly PowerShellXrm.Framework.CI.PowerShell.dll

Set-ExecutionPolicy Unrestricted 
Import-Module -Assembly "PowerShellXrm.Framework.CI.PowerShell.dll"

并出现以下错误。

Import-Module : Cannot bind parameter 'Assembly'. Cannot convert the
"PowerShellXrm.Framework.CI.PowerShell.dll" value of type "System.String"
to type "System.Reflection.Assembly".
At line:1 char:25
+ Import-Module -Assembly PowerShellXrm.Framework.CI.PowerShell.dll
+                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Import-Module], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ImportModuleCommand

PowerShell 脚本保存在与 PowerShellXrm.Framework.CI.PowerShell.dll 程序集相同的位置。我也尝试过包含程序集的完整路径,但没有成功。

最佳答案

如果您想从 DLL 文件导入 PowerShell 模块,只需传递文件名:

Import-Module 'PowerShellXrm.Framework.CI.PowerShell.dll'

如果文件不在 $env:PSModulePath 中列出的文件夹之一中,请使用完整路径:

Import-Module 'C:\path\to\PowerShellXrm.Framework.CI.PowerShell.dll'

documented -Assembly 参数用于导入程序集对象,而不是程序集文件

-Assembly<Assembly[]>

Imports the cmdlets and providers implemented in the specified assembly objects. Enter a variable that contains assembly objects or a command that creates assembly objects. You can also pipe an assembly object to Import-Module.

关于powershell - 导入模块组装错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34194981/

相关文章:

validation - 通过 ValidateScript 属性将默认参数值与验证相结合

PowerShell:导入模块,但没有可用的 "ExportedCommands"

c# - 使用 Import-Module 导入时,C# 二进制文件中的 Cmdlet 不会导出

android - 错误 :No such property: GROUP for class: org. gradle.api.publication.maven.internal.ant.DefaultGroovyMavenDeployer

android - 找不到 Gradle DSL 方法 : 'compileSdkVersion()' after importing a module into the project

powershell - 抑制导入模块的 VERBOSE

powershell - 测试路径 - 使用变量时路径中存在非法字符

powershell - Get-ChildItem文件/文件夹

C# 从 powershell 脚本获取变量

Powershell - 在路径中使用通配符来搜索特定子文件夹中的文件名