Powershell - Windows 更新后创建 ServerManager 对象时出错

发布于 2024-10-28 18:25:03 字数 1020 浏览 4 评论 0原文

您好,

我有一个 powershell 部署脚本,它将文件从 svn 下载到目录中,然后更新 IIS 设置以将站点指向新文件夹。它一直运行良好,直到对服务器进行了一些更新。现在,当我尝试运行该脚本时,它出错了。

[Void][Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
$serverManager = New-Object Microsoft.Web.Administration.ServerManager

错误是

New-Object : Exception calling ".ctor" with "0" argument(s): 
"Retrieving the COM class factory for component with CLSID {B15183DD-75F9-42DF-8E57-C8B57692F134} failed due to the following error: 80040154."
At C:\Users\administrator.LAYERXNETWORKS\AppData\Local\Temp\2\e72ec49f-353f-4dc0-877c-ef67f6b49bab.ps1:2 char:28
+ $serverManager = New-Object <<<<  Microsoft.Web.Administration.ServerManager
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId :    ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

我读到此错误通常是由于未安装该类引起的。

服务器运行 Windows 2008 R2 和 IIS 7.5

HI,

I have a powershell deployment script that downloads files from svn into a directory and then updates the IIS settings to point the site at the new folder. It has been running fine, until some updates were made to the server. Now, when I try and run the script it errors out on

[Void][Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
$serverManager = New-Object Microsoft.Web.Administration.ServerManager

The error is

New-Object : Exception calling ".ctor" with "0" argument(s): 
"Retrieving the COM class factory for component with CLSID {B15183DD-75F9-42DF-8E57-C8B57692F134} failed due to the following error: 80040154."
At C:\Users\administrator.LAYERXNETWORKS\AppData\Local\Temp\2\e72ec49f-353f-4dc0-877c-ef67f6b49bab.ps1:2 char:28
+ $serverManager = New-Object <<<<  Microsoft.Web.Administration.ServerManager
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId :    ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

I ahve read that this error is generally caused by the class not being installed.

The server is running Windows 2008 R2 with IIS 7.5

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如果没结果 2024-11-04 18:25:03

确保加载正确的按位版本的 PowerShell。如果您运行的是 64 位版本,那么您将收到所描述的异常。

您需要使用 32 位 (Windows PowerShell (x86)) 版本的 PowerShell 来使用 Microsoft.Web.Administration

Make sure you load the correct bit-wise version of PowerShell. If you're running the 64 bit version then you'll get the exception described.

You need to use the 32bit (Windows PowerShell (x86)) version of PowerShell to consume Microsoft.Web.Administration.

遮了一弯 2024-11-04 18:25:03

作为答案的补充,我发现使用 x86 powershell 控制台存在问题,最终发现使用

[System.Reflection.Assembly]::LoadFrom( "C:\windows\system32\inetsrv\Microsoft.Web.Administration.dll" )

而不是

[Void][Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")

它运行良好。

Just as an extra to the answer, I found issues with using the x86 powershell console, and in the end found that using

[System.Reflection.Assembly]::LoadFrom( "C:\windows\system32\inetsrv\Microsoft.Web.Administration.dll" )

rather than

[Void][Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")

It ran fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文