-1

我有一个 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 或命令中工作?

谢谢

4

1 回答 1

1

您可以使用解决方法

[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.Smo')

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

方法加载失败,因为它加载了一个给定名称的长形式的程序集,但您的 ar 将部分名称传递给它:阅读此处。而且我发现在 ISE 中工作真的很奇怪,对我来说失败了!

于 2013-04-11T04:36:48.370 回答