2015-12-10 52 views
1

我正在尝试编写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程序集相同的位置。我也试过包括没有运气的组装路径。

+1

'-Assembly'参数想'Assembly'对象不路径。 – PetSerAl

+0

[使用PowerShell运行我的第三方DLL文件]可能的重复(http://stackoverflow.com/questions/7972141/run-my-third-party-dll-file-with-powershell) – vonPryz

回答

1

如果你想导入一个DLL文件中的PowerShell模块简单地传递文件名:

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

如果文件不位于$env:PSModulePath列出的一个文件夹使用的完整路径

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

由于documented-Assembly参数是进口组装对象,没有装配文件

- 装配<大会[] >

导入在指定的组件对象实现的cmdlet和提供。输入包含程序集对象的变量或创建程序集对象的命令。您还可以将汇编对象传送到Import-Module。