2015-12-10 51 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。