Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 766
Barry Gallagher Avatar asked Mar 12 '15 16:03

Barry Gallagher


People also ask

How do I stop IIS remotely?

If it is IIS website, you may consider of using “IISReset /Stop/Start /ReStart” to stop/start the IIS website. Remote control the IIs Website via “Invoke-Command”. Please Note: Since the web site is not hosted by Microsoft, the link may change without notice.

How do I start and stop an application in IIS?

Open IIS Manager and navigate to the web server node in the tree. In the Actions pane, click Start if you want to start the web server, Stop if you want to stop the web server, or Restart if you want to first stop IIS, and then start it again.

How do I stop application pool?

How to Stop Application Pools Using the IIS Manager. On the Connections pane, expand the server node and click Application Pools to display all Application Pools. On the Application Pools page, select the application pool for the published application that is running. Click Stop to stop the application pool.

Does stopping IIS stop application pools?

Stopping a site does not stop the application pool associated with the site. In fact the worker process serving the site still exists and the code loaded in the worker process still exists.


2 Answers

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" } 
like image 196
Mathieu Buisson Avatar answered Sep 19 '22 14:09

Mathieu Buisson


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" } 
like image 33
Zachary Avatar answered Sep 16 '22 14:09

Zachary