How to remotely stop/start an application pool in IIS 8

与世无争的帅哥 提交于 2019-12-20 10:26:16

问题


Caveat: using one line each!

I had these commands for use in IIS 6, and they worked just fine.

Start:

(get-wmiobject -namespace 'root\MicrosoftIISv2' -computername 'REMOTE_SERVER' -class 'IIsApplicationPool' | where-object {$_.Name -eq 'W3SVC/AppPools/MY_FANCY_APPPOOL'}).InvokeMethod('Stop', $null)"

-and-

Stop:

(get-wmiobject -namespace 'root\MicrosoftIISv2' -computername 'REMOTE_SERVER' -class 'IIsApplicationPool' | where-object {$_.Name -eq 'W3SVC/AppPools/MY_FANCY_APPPOOL'}).InvokeMethod('Start', $null)

I'm looking for an alternative in IIS 8. I need a couple of one-liners and they must be Powershell commands. I'm invoking them via a InvokePowerShellCommand activity in TFS. Is there anyone out there who can help me out?


回答1:


You can do the following to start your application pool :

Invoke-Command -ComputerName "REMOTE_SERVER" -ScriptBlock { Start-WebAppPool -Name "MY_FANCY_APPPOOL" }

You can do the following to stop your application pool :

Invoke-Command -ComputerName "REMOTE_SERVER" -ScriptBlock { Stop-WebAppPool -Name "MY_FANCY_APPPOOL" }



回答2:


To start, sometimes you need to add an explicit wait so that the app pool responds to control messages:

Invoke-Command -ComputerName "$REMOTE_SERVER" -ScriptBlock { Import-Module WebAdministration; Start-Sleep -s 10; Start-WebAppPool -Name "$APP_POOL_NAME" }

And to stop:

Invoke-Command -ComputerName "$REMOTE_SERVER" -ScriptBlock { Import-Module WebAdministration; Stop-WebAppPool -Name "$APP_POOL_NAME" }


来源:https://stackoverflow.com/questions/29014761/how-to-remotely-stop-start-an-application-pool-in-iis-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!