Server 2019 setup.
I presently have a task in task scheduler set up to send an e-mail "on event", with any one of multiple events as a trigger. Specifically, it sends an e-mail on any event that indicates a possible hard drive problem that can/will lead to failure. For example, if event ID 52 (Hard Drive Failure Imminent) is generated in the event log, this will run the task and send the admin an email. The task itself is a powershell script that sends the actual e-mail.
Is there a way in the script that I can "capture" the event ID that triggered the task and include it in the e-mail? I'm thinking there must be some common variable that I can insert, like %errorlevel% for example. The part of the script that generates and sends the email is this:
$EmailTo = "firstname.lastname@example.org"
$EmailFrom = "email@example.com"
$Subject = "Hard Drive Failure May Be Imminent!"
$Body = "The system has detected a hard drive failure may be imminent.."
$SMTPServer = "smtp.server.net"
$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("firstname.lastname@example.org", "password");
Thanks for any assistance you can provide.