Jump to content

Notification via email


Recommended Posts

  • Administrators

le this is beyond the scope of this forum, I've found the following:

Step 1: Create a PowerShell Script

First, you need a PowerShell script that sends an email. Here’s a basic example:

 

$filter = "*[System[EventID=7036] and EventData[Data='YourServiceName']]"
$A = Get-WinEvent -LogName System -MaxEvents 1 -FilterXPath $filter
$Message = $A.Message
$EventID = $A.Id
$MachineName = $A.MachineName
$Source = $A.ProviderName

$EmailFrom = "your-email@example.com"
$EmailTo = "recipient-email@example.com"
$Subject = "Alert from $MachineName"
$Body = "EventID: $EventID`nSource: $Source`nMachineName: $MachineName `n$Message"
$SMTPServer = "smtp.your-email-provider.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SMTPServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("your-email@example.com", "your-email-password")
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

Step 2: Set Up a Scheduled Task

  1. Open Task Scheduler and create a new task.
  2. General Tab: Name your task and set it to run whether the user is logged on or not.
  3. Triggers Tab: Create a new trigger that starts the task on an event. Use the following settings:
    • Log: System
    • Source: Service Control Manager
    • Event ID: 7036
  4. Actions Tab: Create a new action to start a program. Set the program/script to powershell.exe and add the following arguments:
    -File "C:\Path\To\Your\Script.ps1"
  5. Conditions and Settings Tabs: Adjust these as needed, but the defaults should work fine.

Step 3: Test Your Setup

Manually start and stop the service to ensure the script runs and you receive the email notifications.

This setup will send an email whenever the specified service starts or stop. If you need more detailed filtering or customization, you can modify the PowerShell script and the event filter accordingly.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   1 member

×
×
  • Create New...