2012-05-11 184 views
2

伊夫停止網站有一個腳本停止站點:使用PowerShell腳本

param($HostName = "localhost", $SiteName) 

$server = $HostName 
$siteName = $SiteName 
$iis = [ADSI]"IIS://$server/W3SVC" 
$site = $iis.psbase.children | where { $_.keyType -eq "IIsWebServer" -AND $_.ServerComment -eq $siteName} 
$site.start() 

# SIG # Begin signature block ... 

但是,當我與高安全性策略的服務器上運行該腳本,我得到這個錯誤:

The following exception was thrown when trying to enumerate the collection: "Unknown error (0x80005000)". 
At D:\DeploymentScripts\Common\StopSite.ps1:6 char:8 
+ $site = <<<< $iis.psbase.children | where { $_.keyType -eq "IIsWebServer" -AND $_.ServerComment -eq $siteName} 
    + CategoryInfo   : NotSpecified: (:) [], ExtendedTypeSystemException 
    + FullyQualifiedErrorId : ExceptionInGetEnumerator 

從如果我沒有訪問IIS,可能會發生這種情況,但是我以管理員身份運行腳本,應該不會授予我需要的訪問權限嗎?

網絡管理模塊是否提供更多訪問權限? 我不會導入這個,因爲我不必在其他服務器上這樣做,如果我需要導入web管理那裏有另一個問題,當我嘗試我得到一個錯誤,說WebAdministrationAliases.ps1沒有數字簽名。 ..

我已經測試了其他服務器上的腳本沒有問題,但是這一個獲得了上面提到的更嚴格的策略,而且它沒有更改策略的選項。

我在Windows Server 2008 R2和IIS 7.5上運行它。

+1

您是否試過[PowerShell IIS模塊](http://www.iis.net/download/powershell)?查看[Stop-Website](http://technet.microsoft.com/en-us/library/ee790607.aspx)。 –

+0

您鏈接到的PowerShell iis模塊是7.0, 和使用7.5使用模塊的即時通訊的管理單元,並且不是iis模塊與webadmin模塊相同嗎? – Roise

+0

它也適用於IIS 7.5,http://learn.iis.net/page.aspx/429/installing-the-iis-powershell-snap-in/ –

回答

7
Import-Module WebAdministration 
Stop-WebSite 'Default Web Site' 
Start-WebSite 'Default Web Site' 
+1

我有「導入模塊Web管理」問題,如果我運行它說它已經導入:[link](http://technet.microsoft.com/en-us/library/ee790599 .aspx),但如果我運行:「導入模塊 - 名稱webadministration」我得到沒有數字簽名的錯誤。並且Stop-WebSite不被識別爲命令 – Roise

+0

什麼是您的執行策略(Get-ExecutionPolicy)?在調用import-module之前,您應該將其設置爲適當的級別。 –

+0

我的執行策略是AllSigned – Roise