【问题标题】:Running Powershell scripts from .NET using WebAdministration snap in使用 WebAdministration snap 从 .NET 运行 Powershell 脚本
【发布时间】:2011-12-22 19:21:53
【问题描述】:

我正在编写一个小型 Web 应用程序,它将在 localhost 上运行一些 powershell 脚本以创建新的 IIS 站点等。我的脚本在 ISE 64 位中运行良好,但是当尝试在 32 位中运行它们时,我得到了像这样的错误:

Get-ChildItem IIS:\Sites
Get-ChildItem : Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154.

我已尝试下载该管理单元的 x86 版本,但安装程序停止告诉我使用“程序和功能”来安装它,我已尝试过但找不到应该启用的功能。

这是一个问题,因为 .NET 应用程序似乎在 32 位 powershell 中运行脚本,所以我的 2 个问题是:

  1. 我可以从 .NET 以 64 位运行这些脚本吗
  2. 我可以在 64 位操作系统上以 32 位安装这些管理单元吗

【问题讨论】:

  • 虽然项目暂时搁置,但遗憾的是仍未找到解决方案
  • 根据 Windows 服务器操作系统,WebAdministration 模块/snapin 可能不存在。见related SO post

标签: c# .net powershell 32bit-64bit


【解决方案1】:

PowerShell 安装 32 位和 64 位 WebAdministration 模块。创建运行空间时,是否在尝试使用 IIS: 驱动器(提供程序)之前执行 Import-Module WebAdministration

【讨论】:

  • 是的,我在 Powershell 32 和 64 中运行相同的脚本。如果我只使用如下的简单脚本:import-module WebAdministration;获取网站 |其中 {$_.Name -eq "ExampleSite"} 我得到:Get-Website : Retrieving the COM class factory for component.... 在 64 位 powershell 中工作正常
  • 您是否以管理员身份运行(如果在启用 UAC 的 Vista/Win7 上提升)。在 C# exe 中,Main 用什么公寓装饰(STA 或 MTA)?还可以尝试将应用程序的平台目标设置为 x64,看看它是否适用于 yrou x64 系统。如果可行并且您需要同时支持 x86 和 x64,请尝试将 Platform Target 设置为 AnyCPU。顺便说一句,其他人也遇到了这个问题。见forums.iis.net/t/1163290.aspx
猜你喜欢
  • 2023-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-13
  • 2019-12-02
  • 2019-09-30
  • 2021-09-11
  • 1970-01-01
相关资源
最近更新 更多