Friday, September 5, 2014

VB script to start stopped app pools

This VB script will start the stopped app pool and send email to desired email address, also it will exclude the undesired apppool. It will send email only and after if a apppool was stopped and started by this script:
=========================================================================


Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
Set oAppPools = oWebAdmin.InstancesOf("ApplicationPool")
'Search in all App Pools
For Each oAppPool In oAppPools
 IF (oAppPool.name <> "Devtesting" ) Then
   IF oAppPool.GetState= 1 Then
 'wscript.echo "App Pool Started"
 
 ElseIF  oAppPool.GetState= 3 Then
   'wscript.echo "App Pool Stopped"
   ' Following command Starts App Pool
    oAppPool.Start
   temp = temp & ", " & oAppPool.Name
    END IF
END IF
Next
 IF (temp <> "") Then
  Set objMessage = CreateObject("CDO.Message")
  objMessage.Subject = "Monitoring APP POOLS on SP Farm"
  objMessage.From = "santosh.sethi@gmail.com"
  objMessage.To = "santosh.sethi@gmail.com"
   objMessage.TextBody = "Monitorinig Message, App Pool: "   & temp & " was down and automatically started."

  '==This section provides the configuration information for the remote SMTP server.
  '==Normally you will only change the server name or IP.
  objMessage.Configuration.Fields.Item _
  ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  'Name or IP of Remote SMTP Server
  objMessage.Configuration.Fields.Item _
  ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTP server name"
  'Server port (typically 25)
  objMessage.Configuration.Fields.Item _
  ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  objMessage.Configuration.Fields.Update
  '==End remote SMTP server configuration section==
  objMessage.Send
 END IF
set oWebAdmin = nothing
Set oAppPools = nothing
Set objMessage = nothing


**Reference link : http://msdn.microsoft.com/en-us/library/ms691445(v=vs.90).aspx