Sending an Email When an Event Happens (Windows Server and Powershell)

So... we got these servers a couple years ago, and the event logs don't email me things anymore. It was one of those things that I forgot to check because it's something you just don't check, but it's important. I ended up seeing the alerts late. No harm - no foul, but it still sucks.

The problem is, the latest Windows servers don't have a built-in feature to email events from the event log. The fix is to run a PowerScript script to send the message.

You can also just paste in the command to execute, but I prefer to run a script.

This shows you how to set up a task from within the Event Log viewer. The emailing part is obsolete:

Instead, you run a script to send the message. To run scripts, you need to enable script execution on the machine. I set the permission to RemoteSigned for the LocalMachine.

This is an elaborate script that sends a message, but it's not what I'm using:

What I'm using is attached. It accepts a single command parameter so that each message can be customized just a little bit, to give the reader a clue:

My email address is hard coded in the script attached, so you'll have to edit it before using it. I installed it in C:\Users\Public\Bin\

sendalert.ps1401 bytes