2009-08-31 102 views
11

我有兩臺服務器Server A和Server B.我想使用Powershell腳本遠程停止服務器A.如何使用PowerShell腳本遠程啓動/停止IIS 6.0/7.0?

+0

我們需要一些關於您的域配置的更多信息。兩臺服務器是否在同一個域中運行,即單個用戶帳戶在服務器上具有相同的權限? – 2009-08-31 12:55:22

+0

也應該將這個問題轉移到服務器故障。 – 2009-08-31 13:00:42

回答

14

最簡單的方法之一就是使用PsExec執行命令行。發送到機器

IISRESET/STOP或/ START或/重啓

所以,你會做這樣的事

PsExec \\Server2 -u Administrator -p somePassword IISReset /STOP 

只是要小心,密碼管理,如果你走這條路線或任何涉及某種類型管理員級別帳戶模擬的路由,以便任何人都無法獲得管理員密碼的純文本副本。

9

因爲你問PowerShell的:

(Get-WmiObject Win32_Service -ComputerName ServerA -Filter "Name='iisadmin'").InvokeMethod("StopService", $null) 
同意這個問題

應移至ServerFault。

3
$service = Get-WmiObject -computer 'ServerA' Win32_Service -Filter "Name='IISAdmin'" 
$service 
$service.InvokeMethod('StopService',$Null) 
start-sleep -s 5 
$service.InvokeMethod('StartService',$Null) 
start-sleep -s 5 
$service.State 

$service = Get-WmiObject -computer 'ServerB' Win32_Service -Filter "Name='IISAdmin'" 
$service 
$service.InvokeMethod('StopService',$Null) 
start-sleep -s 5 
$service.InvokeMethod('StartService',$Null) 
start-sleep -s 5 
$service.State 
2

在的powershell 2.0,運行從CMD提示符下:

invoke-command -computername <yourremoteservername> -scriptblock {iisreset} 
10

選項1:

iisreset remotepcname /restart 

選項2:

(Get-Service -ComputerName remotepc -Name 'IISAdmin').stop() 

選項3:

Invoke-Command -ComputerName remotepc -ScriptBlock {iisreset} 
+0

完美答案。謝謝。 – 2013-08-08 20:39:00

0

您可以使用不同的命名空間的不同版本的IIS V6或V7的,下面流水線命令得到-WmiObject可以cmdlt可以在IIS本地或遠程

的IIS V6

$srv = "Server Name or IP Address" 

$app = "Name of App Pool" 

$x = get-wmiobject -namespace "root\MicrosoftIISv2" -class "IIsApplicationPool" -ComputerName $srv -Authentication PacketPrivacy | where-object {$_.Name -eq "W3SVC/AppPools/$app"} 

$x.Stop() 

$x.Start() 

for IIS v7 

$srv = "Server Name or IP Address" 

$app = "Name of App Pool" 

$x = Get-WMIObject -Namespace "root\webAdministration" -Class "ApplicationPool" -ComputerName $srv -Authentication PacketPrivacy | Where-Object {$_.Name -eq $app} 

$x.Stop() 

$x.Start() 
用於這樣的操作

您需要對這些操作擁有足夠的帳戶權限,但我更喜歡爲我的網站執行$ x.Recycle()。

相關問題