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!

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:

Here is my nifty PowerShell script to monitor application pools on all SharePoint web front-end servers.

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 = ""
        # Use commas for multiple addresses
        $emailTo = ""
        $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 the 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 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 - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

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

  • 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

Your email address will not be published. Required fields are marked *