Ken Andersen's blog about technology related subjects.
Monday, March 6, 2017
Dell OMSA Email Alerts via PowerShell
The SMTP server at my work has become quite unreliable. This is why I wasn't receiving email alerts from my Dell servers in my previous post. Also, in a web application that we host, students weren't getting email alerts that they should have been receiving. We changed that web application to use Office 365's SMTP server and email alerts have become reliable again. On the Dell servers, I was using an application I found called DellSMTPNotify.exe It worked great when our own SMTP server was reliable. It was time to take advantage of the more reliable SMTP server of our hosted Office 365 Exchange setup, but you have to use TLS encryption over SMTP to use Office 365. The DellSMTPNotify program does not support SSL or TLS encryption over SMTP as far as I can tell. It was time to investigate other solutions.
I found a PowerShell script called OMSA-Notify that someone had already written. You can, indeed, use PowerShell to send email over an encrypted connection. I just needed to figure out how to modify the OMSA-Notify script to suit my needs.
I got everything configured, so I thought, but the script just wasn't working. PowerShell just seemed to be sitting idle and would eventually give a timeout error. That's when I realized I was trying to connect to an SMTP server on the public internet, but I was running all of this on a server that was behind a proxy server. I thought I would just try and configure PowerShell to use the proxy server to send my SMTP commands, but that didn't work either. My research led me to the conclusion that SMTP commands can't be send over an HTTP proxy without installing some sort of relay program. I was at a dead end.
Later on, however, it hit me that I could setup a remote PowerShell session to one of our servers that is using a public IP address in front of the proxy server. My co-worker had already setup something similar in a PowerShell script that connects to our Microsoft Data Protection Manager server to setup automatic backups from individual client machines. To setup a server to accept remote PowerShell sessions, you simply need to run "enable-psremoting" from a PowerShell session running as Administrator. That should do it.
After getting remote PowerShell setup, my script was still failing. The smtp.send command wouldn't work because the mail message wasn't being passed to the remote session properly. I then had to setup the passing of parameters into the remote PowerShell session and actually construct the mail message in the remote session. You simply use the "-ArgumentList" parameter to send local variables to the remote PowerShell, as seen in the Invoke-Command line in the script.
Invoke-Command -Session $RoutableServer -ScriptBlock $ScriptBlockContent -ArgumentList $body, $AlertType, $env:COMPUTERNAMEThis was a fun project to figure out. I'm really happy to have server alerts coming to my inbox again. Here's a pastebin of the full modified OMSANotify.ps1: http://pastebin.com/wvvkNaVk
© The Ramblings of Ken Powered by Bootstrap , Blogger templates and RWD Testing Tool
No comments :
Post a Comment