Application Pool Monitoring for SharePoint using PowerShell Script

If SharePoint Application Pools are stopped that would cause “Service Unavailable” outages to your SharePoint environment! While SCOM can monitor the SharePoint IIS web application’s application pool status, it makes it a bit noisier with alerts and doesn’t start the application pool automatically – when stopped. So, let’s 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:

  • 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!)

PowerShell script to Monitor IIS Application Pool statues:

Import-Module WebAdministration

#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: $($ in stopped state at the server : $($Server) on $($now)" >> $LogFile
        "Trying to Start the application Pool...">> $LogFile
        #Try Starting the application Pool
        Start-Sleep -s 10
        "Application Pool's current Status: $($AppPool.State)" >> $LogFile

        #Send Alert-Mail message
        $emailFrom = "[email protected]"
        # Use commas for multiple addresses
        $emailTo = "[email protected]"
        $subject = "Application Pool: $($AppPool.Name) in stopped state in Server: $($Server) at $($now)"
        $body = "Hi SharePoint Team, `n `n The Application Pool $($ 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 = "" #IP or HOST Name of SMTP Server
        $smtp = new-object Net.Mail.SmtpClient($smtpServer)
        $smtp.Send($emailFrom, $emailTo, $subject, $body) 

Here is the sample alert from IIS AppPool monitoring script:

Application Pool Monitoring for SharePoint using PowerShell

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

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

2 thoughts on “Application Pool Monitoring for SharePoint using PowerShell Script

  • November 22, 2020 at 9:50 PM

    Does not run on Server 2012 R2 Datacenter With IIS 8.0

    The specified module ‘WebAdministration’ was not loaded because no valid module file was found in any module directory.


Leave a Reply