IIS APPPool Monitoring Using PowerShell & PSEXEC

Hi Readers,

Sharing a method that We have used to Monitor App Pools as our monitoring tool doesn’t have that capability but with the Power of PowerShell & little bit of trick of PSEXEC we have achieved this.

Extract the ZIP file from below link and edit the batch & .ps1 files

https://gallery.technet.microsoft.com/scriptcenter/IIS-APPPool-Using-14ae7838

First step is to edit the copyscript.bat & add the server Names for which you want to enable monitoring.(This is one time activity)

I have chosen the common path (e:\scripts) here from which script should be executed from the servers.

Edit the .ps1 file & update the email parameters for alerting

$smtpServer = “smtpserver”

$fromadd = “SystemMonitoring@labtest.com”

$email1 = “vikassukhija@labtest.com”

AND Add the apppools that you want to  monitor, My script has examples as below:

Monitorsitepool “Sharepoint – 80”

Monitorsitepool “MySites – 80”

Monitorsitepool “Teams – 80”

Monitorsitepool “SharePoint Central Administration v4”

Now just edit the AppPoolMon.bat which you will schedule it from remote server (may be every 15 mins pr 30 mins)

Now you will get alerts if IIS apppool is down 🙂

############################################################################## 
#                Author: Vikas SUkhija 
#         Date: 8/25/2014 
#                Description: SCript to Monitor IIS Pools 
#                Written for Sharepoint Enviornment 
############################################################################## 
 
$smtpServer = "smtpserver" 
$fromadd = "SystemMonitoring@labtest.com" 
$email1 = "vikassukhija@labtest.com" 
 
 
Import-Module WebAdministration 
 
 
Function Monitorsitepool ($IISSite)  
 
{ 
 
$Apppool = Get-Item "IIS:\Sites\$IISSite" | Select-Object applicationPool 
 
$ApppoolState = Get-WebAppPoolState $Apppool.applicationPool 
$apppoolname = $Apppool.applicationPool 
$hostn = hostname 
 
 
if($ApppoolState.Value -ne "Started") 
   
  { 
  Write-host ""$Apppool.applicationPool" for Site $IISSite is not running on server $hostn" -foregroundColor Red 
  $subj = "Event Notification : OPEN CRITICAL : $apppoolname pool for Site $IISSite is not running on server $hostn" 
  $msg = new-object Net.Mail.MailMessage 
  $smtp = new-object Net.Mail.SmtpClient($smtpServer) 
  #Mail sender 
  $msg.From = $fromadd 
  #mail recipient 
  $msg.To.Add($email1) 
  $msg.Subject = $subj 
  $msg.Body = $subj 
  $smtp.Send($msg) 
  } 
Else 
  { 
  Write-host ""$Apppool.applicationPool" for Site $IISSite is running" -foregroundColor Green 
  <#$subj = "Event Notification : OPEN CRITICAL : $apppoolname pool for Site $IISSite is running on server $hostn" 
  $msg = new-object Net.Mail.MailMessage 
  $smtp = new-object Net.Mail.SmtpClient($smtpServer) 
  #Mail sender 
  $msg.From = $fromadd 
  #mail recipient 
  $msg.To.Add($email1) 
  $msg.Subject = $subj 
  $msg.Body = $subj 
  $smtp.Send($msg)#> 
  } 
 
} 
 
 
 
Monitorsitepool "Sharepoint - 80" 
Monitorsitepool "MySites - 80" 
Monitorsitepool "Teams - 80" 
Monitorsitepool "SharePoint Central Administration v4" 
 
 
################################################################################################## 

Regards

Sukhija Vikas

http://msexchange.me

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s