Accelerating the Exchange Server shut down process

by Amit Zinman [Published on 23 April 2004 / Last Updated on 23 April 2004]

What do you do when your Exchange server takes a long time to shut down? Here is a short simple way to speed up your Exchange server shutting down.

You've probably encountered this before: Some Exchange servers take a long time to shutdown, more than seems reasonable, especially when the server is also a domain controller. For those of you experienced with troubleshooting Exchange quirks, you've probably browsed the newsgroups and support forums and found out that shutting down the Exchange services greatly speeds up the process of shutting down a server.

However, sometimes you might want to be able to automate this for different reasons. You might want a UPS utility to be able to do this automatically. Sometimes you might forget about the need to shutdown the services and then hit your forehead real hard for not remembering and having to wait twenty minutes for a server to shut down.

So, first of all you need a VBScript that shuts down services:

 servername = "localhost"
 set wmi = getobject("winmgmts://" & servername)
 StopService ("Microsoft Exchange System Attendant")
 StopService ("IIS Admin Service")
 StopService ("Netlogon")

Sub StopService (ServiceName)
         wql = "select state from win32_service " _
               & "where displayname='"& ServiceName & "'"
         set results = wmi.execquery(wql)
         for each service in results
            if service.state = "Running" then
             service.stopService
            end if
          next
End Sub

The script is written specifically for Exchange 2003 where IIS processes and Exchange core processes are not interdependent. For Exchange 2000 servers you might consider removing the line that shuts down the System Attendant as it is shut down anyway when you shutdown IIS. Please note that you can also run this script remotely. Simply change the server name from "localhost" to the name of the server being shutdown.

If you also need to shutdown a server remotely you can also run the following piece of VBScript code.

strComputer = "MyExchange"
Set objWMIService = GetObject("winmgmts:" _
     & "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer &
"\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
       ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
       ObjOperatingSystem.Shutdown()
Next

If you really want this to be bullet proof you can also add it to the local or domain policy so it runs before a server is shutting down on all the Exchange servers that you choose.

So, with some tweaking of Active Directory and smart use of some VBScript code, no more waiting for servers is necessary.

Featured Links