Quantcast
Channel: All Forums
Viewing all articles
Browse latest Browse all 27852

How do you obtain a scheduled restart time for an Application Pool via WMI...

$
0
0

Hello!

I am working on a VBScript to get various IIS settings for a set of IIS Servers (Win 2k8 R2 with IIS 7.5).

I am able to remotely connect to \root\WebAdministration and get .InstancesOf("ApplicationPool").  I have been able to get the AppPool name, version of .Net and other values off of ApplicationPool but I'm having a hard time trying to figure out how to get anything out of ApplicationPool.Recycling.PeriodicRestart.Schedule.  I see that is an array of object:ScheduleElement but I have not been able to get that array.

I have tried using InstancesOf, GetArrayData and tried some .Associators calls, but keep getting nothing back (even though I have numerous AppPools that have scheduled restart times).  I want to get this value to make sure that all AppPools that are expected to restart at a scheduled time are configured to do so.

Here's what I have so far...

 

Option Explicit

On Error Resume Next

Dim objWMIService, objAppPool, objAppPools, objApplications, objSched, objSchedules
Dim strComputer, strAppPoolMode

strComputer = "."

Set objWMIService = GetObject("winmgmts:{" _& "impersonationLevel=impersonate," _& "authenticationLevel=pktPrivacy" _& "}!\\" & strComputer & "\root\WebAdministration")

If Err.Number <> 0 Then
    WScript.Echo "ERROR : Failed to get WMI handle [" & Err.Description & "]"
    Err.Clear
Else
	Set objAppPools = objWMIService.InstancesOf("ApplicationPool")
	WScript.Echo "--------------------------"
	For Each objAppPool In objAppPools
		WScript.Echo objAppPool.Name
		WScript.Echo "State: " & GetStateDesc(objAppPool.GetState)
		WScript.Echo "AutoStart: " & objAppPool.AutoStart
		WScript.Echo "Enable32BitAppOnWin64: " & objAppPool.Enable32BitAppOnWin64
		If objAppPool.ManagedPipelineMode = 0 Then
			strAppPoolMode = "Integrated"
		ElseIf objAppPool.ManagedPipelineMode = 1 Then
			strAppPoolMode = "ISAPI"
		End If
		WScript.Echo "ManagedPipelineMode: " & strAppPoolMode
		WScript.Echo "ManagedRuntimeVersion: " & objAppPool.ManagedRuntimeVersion
		WScript.Echo "Recylcing Schedule: " & objAppPool.Recycling.PeriodicRestart.Schedule
		Set objApplications = objAppPool.Associators_(, "Application")
		For Each objApplication In objApplications
			WScript.Echo "Application: " & objApplication.Path
		Next
		Set objSchedules = objAppPool.Recycling.PeriodicRestart.Schedule
		For Each objSched In objSchedules
			WScript.Echo "Restart: " & objSched
		Next
		WScript.Echo "--------------------------"
	Next
End If

Function GetStateDesc(StateCode)
    Select Case StateCode
        Case 0
            GetStateDesc = "Starting"
        Case 1
            GetStateDesc = "Started"
        Case 2
            GetStateDesc = "Stopping"
        Case 3
            GetStateDesc = "Stopped"
        Case 4
            GetStateDesc = "Unknown"
        Case Else
            GetStateDesc = "Attempt to retrieve state failed."
    End Select
End Function


Viewing all articles
Browse latest Browse all 27852

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>