If SharePoint Application Pools are stopped that would cause outages to your SharePoint environment! While SCOM can monitor SharePoint IIS web application's application pool status, it makes bit more noisy with alerts and doesn't start the application pool automatically. So, lets address this issue with the help of PowerShell! Here is my nifty PowerShell script to monitor application pools on all SharePoint web front end servers.
This script not only scans IIS Application Pool status on SharePoint Web-Front end servers, But also:
Schedule this PowerShell script in Windows Task scheduler in any Application server (or any other server will do!) to periodically scan App Pool status, Say once per 5 Min! run interval can be adjusted based on your application priority.
Here is my another post on Scheduling PowerShell scripts using Windows Task scheduler: Create a Scheduled Task for PowerShell Script with Windows Task Scheduler
This script not only scans IIS Application Pool status on SharePoint Web-Front end servers, But also:
- Logs application Pool status if its not in Started state
- Automatically starts AppPool if its in stopped state
- Sends out an Alert-Email to SharePoint Admin team (or whoever configured!)
Import-Module WebAdministrationHere is the sample alert from IIS AppPool monitoring script:
#Array to hold Server names - Change it to YOUR SharePoint front end servers
$WFEServers =("HS-WFE01", "HS-WFE02", "HS-WFE03")
#Log file location
$LogFile = "D:\Scripts\AppPool-Log.txt"
#Loop through each server and Check Application Pool status
foreach ($Server in $WFEServers)
{
$ServerMgr = [Microsoft.Web.Administration.ServerManager]::OpenRemote($Server)
#Get all Application Pools which are not in Started State
$AppPoolColl = $ServerMgr.ApplicationPools | Where-Object {$_.State -ne "Started"}
foreach($AppPool in $AppPoolColl)
{
#Get the time to Log
$now = Get-Date –f "yyyy-MM-dd HH:mm:ss"
#Log to file
"`n Found Application Pool: $($AppPool.name) in stopped state at the server : $($Server) on $($now)" >> $LogFile
"Trying to Start the application Pool...">> $LogFile
#Try Starting the application Pool
$AppPool.Start()
Start-Sleep -s 10
"Application Pool's current Status: $($AppPool.State)" >> $LogFile
#Send Alert-Mail message
$emailFrom = "AppPoolMonitor@crescent.com"
# Use commas for multiple addresses
$emailTo = "SPAdmins@crescent.com"
$subject = "Application Pool: $($AppPool.Name) in stopped state in Server: $($Server) at $($now)"
$body = "Hi SharePoint Team, `n `n The Application Pool $($AppPool.name) was in stopped state in server: $($server). `n`n We tried Re-starting it... Current State of the Application Pool: $($AppPool.State). `n`n Please take necessary actions if its not started !. `n `nThanks, `nSharePoint AppPool Monitoring Script."
$smtpServer = "smtp.crescent.com" #IP or HOST Name of SMTP Server
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
}
}
Schedule this PowerShell script in Windows Task scheduler in any Application server (or any other server will do!) to periodically scan App Pool status, Say once per 5 Min! run interval can be adjusted based on your application priority.
Here is my another post on Scheduling PowerShell scripts using Windows Task scheduler: Create a Scheduled Task for PowerShell Script with Windows Task Scheduler