如何使用PowerShell脚本远程启动/停止IIS 6.0/7.0?

发布于 2024-08-03 08:26:24 字数 62 浏览 3 评论 0原文

我有两台服务器服务器 A 和服务器 B。我想使用 Powershell 脚本从服务器 B 远程停止服务器 A。

I have two servers Server A and Server B. I want to stop server A from Server B remotely using Powershell script.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

贵在坚持 2024-08-10 08:26:24

最简单的方法之一就是使用 PsExec< 进行命令行执行/a>.并向计算机发送

IISReset /STOP 或 /START 或 /RESTART

所以你会做这样的事情

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

如果你走这条路线或任何涉及某种类型的管理员级别帐户模拟的路线,请小心密码管理,这样就没有人可以获得管理员密码的纯文本副本。

One of the simplest ways to do this is really with just a command line execution using PsExec. And send over to the machines

IISReset /STOP or /START or /RESTART

So you'd do something like this

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

Just be careful with password management if you go this route or any route that involves some type of admin level account impersonation so that no one can get a plain text copy of the admin password.

池予 2024-08-10 08:26:24

选项 1:

iisreset remotepcname /restart

选项 2:

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

选项 3:

Invoke-Command -ComputerName remotepc -ScriptBlock {iisreset}

Option 1:

iisreset remotepcname /restart

Option 2:

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

Option 3:

Invoke-Command -ComputerName remotepc -ScriptBlock {iisreset}
阪姬 2024-08-10 08:26:24

因为您要求使用 Powershell:

(Get-WmiObject Win32_Service -ComputerName ServerA -Filter "Name='iisadmin'").InvokeMethod("StopService", $null) 

同意这个问题应该移至 ServerFault。

Because you asked for Powershell:

(Get-WmiObject Win32_Service -ComputerName ServerA -Filter "Name='iisadmin'").InvokeMethod("StopService", $null) 

Agreed this question should be moved to ServerFault.

_畞蕅 2024-08-10 08:26:24
$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
$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
多像笑话 2024-08-10 08:26:24

在 powershell 2.0 中,从 cmd 提示符运行以下命令:

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

In powershell 2.0, run the following from cmd prompt:

invoke-command -computername <yourremoteservername> -scriptblock {iisreset}
郁金香雨 2024-08-10 08:26:24

对于不同版本的 IIS v6 或 v7,您可以使用具有不同名称空间的 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() 。

You can use get-wmiobject cmdlt with different NameSpace for different versions of IIS v6 or v7, below pipelining command can be used for such operations in IIS locally or remotely

for 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()

you need to have sufficient account privilege for these operations, event though i prefer to do $x.Recycle() for my websites.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文