2013-09-21 29 views
4

我試圖自動化一些Web應用程序部署任務,所以我試圖使用PowerShell來實現此目的。 。PowerShell腳本和.bat文件的批處理文件就在那裏執行PowerShell腳本,幷包含這段文字,我在Windows 8 - 。64無法在IIS中運行'dir'或'Get-ChildItem'命令: powershell

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%~dp0\SetupWebServer.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 

從一個單獨的powershell提示符,我可以cd到IIS:\,但我不能運行dir命令並得到類似的錯誤。我錯過了什麼?

回答

9

通過指定SysWOW64您迫使Powershell運行在32位上下文中。 Web管理模塊僅支持64位上下文。

解決方案:

  1. 如果批處理文件運行32位,使用SysNative代替SysWOW64
  2. 如果批處理文件是64位,下降了SysWOW64和使用標準路徑。
+0

已將批處理文件中的路徑更改爲「%windir%\ Sysnative \ WindowsPowerShell \ v1.0 \ powershell.exe」,而且似乎可行。 – sdanna