在命令行中使用powershell时加载程序集错误

时间:2013-04-11 04:24:09

标签: powershell powershell-ise

我有一个load.PS1,它加载'Microsoft.SqlServer.Smo',如下所示

[System.Reflection.Assembly]::load('Microsoft.SqlServer.Smo') | Out-Null

当我使用ISE加载并运行它时效果很好,但是当我在powershell shell中运行它或者使用“powershell -command”时会出现错误。\ RemoveInvalidSSRSAgentJob.ps1 xxxx“如下所示

Exception calling "Load" with "1" argument(s): "Could not load file or assembly
 'Microsoft.SqlServer.Smo' or one of its dependencies. The system cannot find t
he file specified."
At line:1 char:38
+ & {[System.Reflection.Assembly]::load <<<< ('Microsoft.SqlServer.Smo') | Out-
Null}
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

如何设置它以便它可以在powershell shell或命令中工作?

由于

1 个答案:

答案 0 :(得分:1)

您可以使用

解决方法
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.Smo')

但是这种方法被微软公司宣布为“过时”,将来可以消除。

方法加载失败,因为它加载了一个给定长名称的程序集,但是你的ar传递了部分名称:Read here。 我觉得很奇怪,在ISE工作中,对我来说失败了!

相关问题