'------------------------------------------------------------------------------ ' IIS v7 Check state of an application pool ' ========================================= ' ' Author: Nicola BRESSAN (nicola.bressan@gmail.com) ' based on original IIS v6 script by Vincent BESANCON ' ' Usage: ' Check_IISv7_AppPool_State.vbs ' - The name of the application pool. ' ' It returns: ' - OK if state is running. ' - CRITICAL if state is stopped. ' - WARNING if state is stopping or starting. ' - UNKNOWN for all the others (app pool not found, etc...). ' '------------------------------------------------------------------------------ ' ' Args strArgAppPool = Wscript.Arguments.Unnamed.Item(0) Const noError = False ' Establish the connection to the WMI provider Set oWebAdmin = GetObject("winmgmts:root\WebAdministration") ' Search the AppPool passed as argument in the list of application pools Set oAppPool = oWebAdmin.Get("ApplicationPool.Name='" & strArgAppPool & "'") ' Create nice messages for pool states Select Case oAppPool.GetState Case 0 StateDescription = "STARTING" outputStatus = "WARNING! " outputCode = 1 Case 1 StateDescription = "STARTED" outputStatus = "OK! " outputCode = 0 Case 2 StateDescription = "STOPPING" outputStatus = "WARNING! " outputCode = 1 Case 3 StateDescription = "STOPPED" outputStatus = "CRITICAL!! " outputCode = 2 Case 4 StateDescription = "UNKNOWN" outputStatus = "UNKNOWN? " outputCode = 3 Case Else StateDescription = "UNDEFINED VALUE" outputStatus = "UNKNOWN? " outputCode = 3 End Select ' Output Wscript.Echo outputStatus & oAppPool.Name & ": " & StateDescription ' Error handling If noError = true Then ' Error message Wscript.echo "UNKNOWN: Error during the WMI query for app pool " & strArgAppPool & " !" ' Exit & return code WScript.Quit(3) Else ' Clean exit WScript.Quit(outputCode) End If