How to Use Task Scheduler to Monitor/Restart the Events2HVAC Service

In some situations, Windows server updates can reboot the server automatically and depending on when other services come back online, Events2HVAC can fail to start up automatically.  **NOTE:  Only do this is this has been an issue at your server.  Not all servers have this problem.

To prevent this from happening you can create a Task Scheduler task to run the PowerShell script below.  This will check if the Events2HVAC service is running and if it isn't it will send a start command and send a notification email to a user.

Powershell Script checksvcutil1:

# Checks for a service to be running and starts if needed.  Sends an email notification also
# Author:
# Date: 01/16/2012
# Name: checksvculti1.ps1

function FuncCheckService{
param($ServiceName)
$arrService = Get-Service -Name $ServiceName
if ($arrService.Status -ne "Running"){
Start-Service $ServiceName
FuncMail -To "youremail@yourdomain.com" -From "events2hvac@yourdomain.com" -Subject "Events2HVAC service has stopped and was restarted automatically." -Body "$ServiceName stopped and was restarted." -smtpServer "smtp.yourdomain.com"
}
}

function FuncMail {
param($To, $From, $Subject, $Body, $smtpServer)
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = $From
$msg.To.Add($To)
$msg.Subject = $Subject
$msg.IsBodyHtml = 1
$msg.Body = $Body
$smtp.Send($msg)
}

FuncCheckService -ServiceName "Events2HVAC_Service"

Replace your email, domain, and SMTP server settings with your own if you want to send an email.  Save this script to text file c:\PowerShell\checksvcutil1.ps1

Now we just need to run this script periodically.  You use the built in Windows Task Schedule to do this.

1.  Open Task Scheduler - Create Task

Create a name and select "Run whether user is logged in or not".  Check "Run with highest privileges"

mceclip0.png

2.  Enter a new Trigger every 15 minutes

mceclip1.png

3.  Create a new Action

Run Powershell with the parameter as the path to the script file above.

mceclip2.png

4.  Conditions

mceclip3.png

5.  Settings 

mceclip4.png

After hitting OK, you'll be prompted to enter your login credentials that will be used to run the powershell script each time.

Make sure you test the task to make sure it does what you expect.  Select the item, right-click, RUN to trigger the task now.  You can manually stop the Events2HVAC_service and run it again to verify it starts it back up and sends an email.

 

mceclip5.png

 

 

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Article is closed for comments.