English 中文(简体)
如何停止与PowerShell的 IS?
原标题:How to Stop IIS with PowerShell?

我在学习PowerShell, 试图在远程服务器上阻止IIS。

我使用 PowerGUI 脚本编辑器, 我以管理模式开始编辑 。

我有这个密码

$service = Get-WmiObject Win32_Service -ComputerName  myserver   -Filter "Name= IISAdmin "
$service
$service.StopService();
$service.State

州政府总是在奔跑 我不知道为什么它不停止

编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑

运行时出错

Invoke-Command -ComputerName  myserver  { Stop-Service IISAdmin }

Connecting to remote server failed with the following error message : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help topic.

编辑2

我找到了这个,它似乎起作用了。我不知道如何从停止服务公司得到信息,所以我不得不用另一种方式把它给我。如果你知道如何让我知道,请告诉我。

Stop-Service -Force -InputObject $(Get-Service -Computer myserver -Name IISAdmin)
$service = Get-WmiObject Win32_Service -ComputerName  myserver    -Filter "Name= IISAdmin "
$service.State

这个工作原理。 我不明白为什么。我唯一能想到的就是 我不得不使用它,因为它无法阻止服务器,所以,也许这是一个原因?

最佳回答

尝试使用 PsExec 服务器2 - u 管理员 - p somePassword IISReset /STOP 尝试

或使用 PowerGUI 脚本编辑器

$service = Get-WmiObject -computer  ServerA  Win32_Service -Filter "Name= IISAdmin "
$service
$service.InvokeMethod( StopService ,$Null)
$service.State

尝试使用

$server = "servername"
$siteName = "Default Web Site"
$iis = [ADSI]"IIS://$server/W3SVC"
$site = $iis.psbase.children | where { $_.keyType -eq "IIsWebServer" -AND
$_.ServerComment -eq $siteName }
$site.serverstate=3
$site.setinfo()
问题回答
Invoke-Command -ComputerName myserver { Stop-Service W3SVC}

停止 IIS (在 iis- manager 中的服务器上“ 右键单击 & gt; 停止 ” ) :

spsv iisadmin,was,w3svc -pa

意指:

stop-service -name iisadmin,was,w3svc -passThru # -passThru is optional but basically outputs the result

(替代 : < code> gsv iisadmin, w3svc {spsv -pasv -pa_sasv -pa 重新启动服务和输出结果, 但在此示例中, 第二 -pa 是可选的!!!!!!!!! fYI: gsv=get- service, sasv=start- service, spsv=st-service, pa=pass Thru)

您可以用 iisresets 远程停止/ 重新启动 iis :

iisreset [computername]

还有另外一种简单的方法 阻止IIS 仅仅从Powershell逃出来

iisreset /stop

并启动 IIS, 只是

iisreset /start

我不是处理 WMI 对象的粉丝。 相反,我建议使用 < code> isresreset/ stop 来与 PowerShell 重新移动一起使用。 因此, 基本上是这样 :

Invoke-Command -ComputerName  myserver  -ScriptBlock { & iisreset /stop }

您可以用 / stop / start 互换 , 在远程服务器上启动 IIS 。

如果您不想利用 iisressetset.exe ,而是使用纯 PowerShell, 您可以启动/ 停止 W3SVC 服务 :

Invoke-Command -ComputerName  myserver  -ScriptBlock { Stop-Service W3SVC }

stop- service 替换为 start-service 以重新开始。 W3SVC 服务为IIS。





相关问题
Session Management with Windows Authentication

In an ASP.NET web app, using Integrated Windows Authentication, is the session tied to the windows identity? In other words, if I login (using IWA) to the app, and the app stores some "stuff" in my ...

Using Elmah with Cassini

Does anyone know if I can use Elmah with Visual Studio build-in web server(aka Cassini)? I get it working easily on IIS, but using same configuration, it doesn t work with Cassini. When I requested ...

Setting hostname in IIS, include www?

I want to set the hostname for a website I m adding in IIS 7, however do I include the www in the hostname or not? because I want both www.mysite.com and mysite.com both to point to mysite on the ...

inetpub versus any other folder

I ve run websites out of inetpub, as well as from folders just residing on the C: drive. I wonder, are there any definitive advantages to running websites out of inetputwwwroot?

IIS 6.0 hangs when serving a web-service

I am having issues with one of our web-services. It works fine on my development machine (win XP) whether I host it as a separate application or using cassini from Visual studio. Once I deploy on the ...