PowerShell- Monitor Group Of Services on 'N' Servers & Notify Stopped Services

This post explains how to monitor a multiple services on a list of servers and send alert when the given service is in stopped state. This script will allow you to read a list of servers from the input file and establish connection to all remote servers to pull service status.

 
 
 
 
 
4.4 Star
(5)
4,566 times
Add to favorites
11/6/2014
E-mail Twitter del.icio.us Digg Facebook
  • enhancement
    3 Posts | Last post March 23, 2017
    • i love this script . Is it possible to write the results on a table on a database ..success or failure along with date and timestamp 
    • Yes, It's possible. I will work on the requirement and get back to you at the earliest.
      
      Prashanth
      
    • Can you try this link?
      http://www.sqlshack.com/illustration-of-an-example-availability-monitoring-service-using-powershell-and-sql/
      
      Let me know if you need any further assistance on this request.
      
      Best Regards,
      Prashanth
  • getting error like this
    2 Posts | Last post December 20, 2016
    • 
      PS D:\scripts> PS D:\scripts> Get-ServicesStatusAlert -ComputerList D:\scripts\server.txt -includeService SQLSERVERAGENT
      ,MSSQLSERVER -To vinod.punna@aparaa.com -From support@easyrecognition.comt -SMTPMail smtp.office365.com
      >>
      Get-Process : A positional parameter cannot be found that accepts argument 'Get-ServicesStatusAlert'.
      At line:1 char:1
      + PS D:\scripts> Get-ServicesStatusAlert -ComputerList D:\scripts\serve ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidArgument: (:) [Get-Process], ParameterBindingException
          + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetProcessCommand
    • Hi Vinod,
      
      Did you create the Get-ServiceStatusAlert function?
      
      After creating the function, Just call the function
      
      Get-ServicesStatusAlert -ComputerList D:\scripts\server.txt -includeService SQLSERVERAGENT
      ,MSSQLSERVER -To vinod.punna@aparaa.com -From support@easyrecognition.comt -SMTPMail smtp.office365.com
      
      Paste the above content in the PS prompt.
      
      In your error message
      PS D:\scripts> is being called twice.
      
      I hope this is typo error. If not, Please copy the above call and paste in a PS prompt.
      
      Let me know.
      
      Prashanth
      
  • Is script works only for default instance ??
    3 Posts | Last post October 14, 2016
    • I tried this script, But is working only for default instance not for named instance.
      Can i get this script work for both?
      
      Thanks
      Rajesh
    • Hi Rajesh,
      
      Use the displayname insted of service name
      
      The below is the updated script
      
      Foreach($ServerName in (Get-Content $script:list))
      {
      $service = Get-Service -ComputerName $servername
      if ($Service -ne $NULL)
      {
      foreach ($item in $service)
       {
       #$item.DisplayName
       Foreach($include in $includeService) 
           {                       
       write-host $inlcude                                    
       if(($item.displayname).Contains($include) -eq $TRUE)
          {
      	Write-Host  $item.MachineName $item.name $item.Status 
          writeDiskInfo $ServiceFileName $item.MachineName $item.name $item.Status 
          }
          }
       }
      }
      }
      
      
      and call the function like below
      
      Get-ServiceStatusReport -ComputerList C:\server.txt -includeService  "SQL" -To pjayaram@appvion.com -From pjayaram@appvion.com -SMTPMail abc.mail.com
      
      
    • Did you try the script?
  • How to adjust to alert on start pending and stop pending?
    4 Posts | Last post September 16, 2016
    • The reason I sought your wonderful script was because we has a service hung in a starting state. I can see the script outputting StartPending and StopPending but not sure how to get it to alert via email those statuses. I only seems to get Stopped statuses. Thank you in advance!
    • The script is only checking for Stopped status hence you are getting that result.
      
      Please add the condition like below
      
      if( $status -eq "Stopped" -or $status -eq "stopPending" -or $status -eq "startPending") 
      { 
       increment $global:a 
       Add-Content $fileName "<tr>" 
       Add-Content $fileName "<td bgcolor='#FF0000' align=left ><b>$servername</td>" 
       Add-Content $fileName "<td bgcolor='#FF0000' align=left ><b>$name</td>" 
       Add-Content $fileName "<td bgcolor='#FF0000' align=left ><b>$Status</td>" 
       Add-Content $fileName "</tr>" 
      } 
      
      let me know.
      
      Prashanth
    • Yes! Worked like a charm! Much, much, much appreciated. 
    • Great!!!
  • i'm an idiot =)
    2 Posts | Last post September 12, 2016
    • It's running which is why I did not get the email. Its working amazingly! Thanks!
    • Good. thanks for reading my post!!
      
      Prashanth
  • email does not work for me
    1 Posts | Last post September 12, 2016
    • When I run the following from PS:
      
      PS C:\scripts> Get-ServiceSQLAlert -ComputerList C:\scripts\server.txt -includeService WatchDogNT -To b****@m****.com -From tsg****@m****.com -SMTPMail d****.m****.com
      
      I get the following output:
      
      
      ---------------
          Directory: C:\
      
      
      Mode                LastWriteTime     Length Name
      ----                -------------     ------ ----
      -a---         9/12/2016   1:27 PM          0 ServiceFileName.htm
      
      
      testserver WatchDogNT Running
      
      
      PS C:\scripts>
      ---------------
      
      There is a lot of empty space on the output as well. 
      
      I have not made any changes to the PS1 file. And to get the function I used dotting.
11 - 16 of 16 Items