Draining IIS before stopping services

Razzi29 331 Reputation points

Is there a best practice or clean procedure to drain IIS server from current sessions before stopping the services for the purpose of maintenance?

Internet Information Services
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,407 questions
{count} votes

Accepted answer
  1. MotoX80 32,326 Reputation points

    Copy an app_offline page to the root to tell users that maintenance begins in 5 minutes. Then recycle the worker processes.


    Powershell script to start with. Adjust as needed.

    copy-item C:\YourWebStuff\app_offline.htm  -Destination C:\Inetpub\wwwroot\ 
    start-sleep -Seconds (60 * 5)                   # give users 5 minutes to see the message    
    (Get-IISAppPool -Name DefaultAppPool).stop()    # use your pool name
    start-sleep -Seconds 30                         # give it some time
    get-process w3wp | stop-process -force          # kill IIS wp if it won't stop
    # do maintenance here 
    remove-item C:\Inetpub\wwwroot\app_offline.htm      # tell IIS to serve up the site 
    (Get-IISAppPool -Name DefaultAppPool).start()       # restart the app pool  

    If app_offline doesn't work for you, then define 2 sites with the same network bindings. One site is your main app site, the second site is just simple htm pages that show a message that the site is down for maintenance. That second site is stopped by default. When you want to do maintenance, stop the first site and start the second. When maint is complete, stop the second and start the first.

1 additional answer

Sort by: Most helpful
  1. Razzi29 331 Reputation points

    @Yurong Dai-MSFT Appreciate the response, but not quire what I was looking for as I am aware of performing those checks; I was looking more of an automated PowerShell script process or thrid party tool that can provide me a very fast/ quick way of just draining local IIS services on a particular system.

    0 comments No comments