无法从 IIS:\ 在 powershell 中运行"dir"或"Get-ChildItem"命令



我正在尝试自动执行一些Web应用程序部署任务,因此我尝试使用Powershell来完成此操作。 我有一个Powershell脚本和一个.bat文件。 批处理文件只是为了执行 powershell 脚本并包含此文本。 我在Windows 8 - 64位。

C:WindowsSysWOW64WindowsPowerShellv1.0powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%~dp0SetupWebServer.ps1' %*

我在运行以下命令的powershell脚本中有一些代码:

Write-Host "Check for the existence of the Application Pool."
Import-Module WebAdministration
$iisAppPoolName = "SiteName"
$iisAppPoolDotNetVersion = "v4.0"
$iisAppName = "SiteName"
cd IIS:AppPools
if (!(Test-Path $iisAppPoolName -PathType Container))
{
     Write-Host "Creating Application Pool"
}

当我到达CD IIS:\AppPools\命令时,我收到以下错误:

cd : Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the
following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At line:1 char:1
+ cd IIS:AppPools
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Set-Location], COMException
+ FullyQualifiedErrorId : 
System.Runtime.InteropServices.COMException,Microsoft.PowerShell.Commands.SetLocationCommand

从单独的电源外壳提示符,我可以cd到IIS:\,但我无法运行dir命令并得到类似的错误。 我错过了什么?

通过指定SysWOW64,可以强制Powershell在32位上下文中运行。Web 管理模块仅支持 64 位上下文。

溶液:

  1. 如果批处理文件运行的是 32 位,请使用 SysNative 而不是SysWOW64
  2. 如果批处理文件为 64 位,请删除SysWOW64并使用标准路径。

最新更新