Ever had an outage while you were away from the office and you didn't (or couldn't) check your email from your mobile phone? What if your environment could notify administrators via SMS (text) messages about things going on in the environment? It can! For free! If you can't afford to purchase a more robust monitoring and notification system, SMS notifications can be automated internally for free. In this article we'll go over how to send SMS messages using an SMTP server and PowerShell. Click below to view the full .ps1 on github First things first, the purpose of these SMS notifications will determine most of the variables shown. Since this is just for demonstrative purposes, we'll have some fun with it! The Varibles
Here are the variables from our example script: "$Count = 0 The Actions Next up is where all the magic happens. You may recognize this as a classic Do / While statement. That is because we do an action (like send a text) while the count is less than 10, at least in this case. The nice part about this particular script is that each line has text before the action that tells the user what the script is doing. These are optional and can be removed. Let's go through each line and then we'll put it all together. The first step inside the Do statement is to declare the $Count variable. Then the count is displayed to the user. Do { Next we generate a random 12 character string to be used in the from address. This step is not necessary but ensures that the recipient cannot block the messages, because they will always be coming from a different address. If you'd prefer not to generate a random address so that the texts can be viewed in one ongoing thread on a mobile device, simply define the $Sender as some other fixed string. "Generating random number" Next up one of the messages in the array called $Message is selected at random: "Selecting a random message from the Messages variable" Next the actual message is sent based off of the previously defined variables "Sending message" Next a string is shown to the user that the message was sent and the timer starts, using the $Timer variable to show the duration: "Message Sent" Lastly, the while statement keeps count of how many times we've made it back to the while statement. As long as the messages are being sent, it's also counting how many of those have been sent and terminates the script after the count reaches the $MaxCount. Ten in this script. While ($Count++ -le $MaxCount) Finally , here's what we get when we put it all together: # ******************************************************************************** |
RepositoriesAuthorSheridan's interests are in technology, business, music, and adventures Categories
All
Archives
June 2019
|