Import-Module -Assembly错误

时间:2015-12-10 06:17:16

标签: 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程序集相同的位置。我也尝试过没有运气的整个装配路径。

2 个答案:

答案 0 :(得分:2)

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

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

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

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

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

  

<强> - 装配&LT;汇编[] GT;

     

导入在指定的程序集对象中实现的cmdlet和提供程序。输入包含装配对象的变量或创建装配对象的命令。您还可以将程序集对象传递给Import-Module。

答案 1 :(得分:0)

如果要使用-Assembly参数,可以使用以下命令:

$assembly = [System.Reflection.Assembly]::LoadFrom('PowerShellXrm.Framework.CI.PowerShell.dll')
Import-Module -Assembly $assembly
相关问题