Feb 8, 2016

Get notified via email when your VPN connection drops in Windows

Last Friday I mentioned a tool that lets me kill my Bittorrent client if my private VPN connection drops so the fuzz can't catch me in the act of *gasp* downloading my favorite TV shows. Today I will tell you how you can get notified via email if that connection drops so you know when to check on your media server.

This method is similar to my method for notifying you when someone in Active Directory gets locked out. It uses a PowerShell script and a scheduled task that looks for a specific event in the event log, and when that event happens the script is ran and an email is sent off. You can look at my Active Directory script post to see how to setup the scheduled task. For VPN being dropped, the event you want to use as your trigger is:
Log: System
Source: Rasman
EventID: 20268
You can use the following code and tailor it for your environment:



Save the code as vpnfail.ps1 and you should be good to go.

Obviously the above code is for secure email servers that use TLS encryption over port 587 (Like Gmail does). If you're SMTP server doesn't require it you can remove the SSL options.

You can easily test the script first by running it manually via PowerShell, and then again with your scheduled task by disconnecting from VPN.



Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | stopping spam