我正在尝试编写 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/