我有两台服务器服务器 A 和服务器 B。我想使用 Powershell 脚本从服务器 B 远程停止服务器 A。
问问题
48764 次
6 回答
14
最简单的方法之一就是使用PsExec执行命令行。并发送到机器
IISReset /STOP 或 /START 或 /RESTART
所以你会做这样的事情
PsExec \\Server2 -u Administrator -p somePassword IISReset /STOP
如果您走这条路线或任何涉及某种类型的管理员级别帐户模拟的路线,请小心密码管理,这样任何人都无法获得管理员密码的纯文本副本。
于 2009-08-31T13:00:18.523 回答
13
选项1:
iisreset remotepcname /restart
选项 2:
(Get-Service -ComputerName remotepc -Name 'IISAdmin').stop()
选项 3:
Invoke-Command -ComputerName remotepc -ScriptBlock {iisreset}
于 2013-02-22T10:34:09.903 回答
10
因为您要求使用 Powershell:
(Get-WmiObject Win32_Service -ComputerName ServerA -Filter "Name='iisadmin'").InvokeMethod("StopService", $null)
同意这个问题应该移到ServerFault。
于 2009-09-09T20:03:42.943 回答
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
于 2012-01-06T17:55:26.630 回答
2
在 powershell 2.0 中,从 cmd 提示符运行以下命令:
invoke-command -computername <yourremoteservername> -scriptblock {iisreset}
于 2012-06-22T21:00:34.457 回答
0
您可以针对不同版本的 IIS v6 或 v7 使用具有不同 NameSpace 的 get-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()。
于 2013-05-16T07:39:59.843 回答