无法从IIS中运行'dir'或'Get-ChildItem'命令:\来自powershell

sda*_*nna 4 iis powershell windows-8

我正在尝试自动执行一些Web应用程序部署任务,因此我尝试使用PowerShell来实现此目的.我有一个powershell脚本和一个.bat文件.批处理文件就在那里执行powershell脚本并包含此文本.我在Windows 8 - 64位.

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%~dp0\SetupWebServer.ps1' %*
Run Code Online (Sandbox Code Playgroud)

我在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"
}
Run Code Online (Sandbox Code Playgroud)

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

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
Run Code Online (Sandbox Code Playgroud)

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

Eri*_*ris 10

通过指定SysWOW64您强制Powershell在32位上下文中运行.WebAdministration模块仅支持64位上下文.

解:

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