I really like this script for sending SMS using SCOM. Though it has some bugs in it’s current form. I also do not have a Twilio account. That is why I decided to rewrite some of the logic to use generic HTTP SMS gateways. Currently it is set up for using pswincom sms gateway, though this can easily be changed to some other service. Though you will need to find out how to construct the URL for that service and change the code in the CreateSMSurl function to match.The PSWinCom details are here.
- Exclusion for when not to send SMS messages had some issues
- Multiple entries on a subscriber was not handled correctly by the script
- Fixed an issue where phone numbers was not excluded if schedule was violated
- Removed where-object logic to make code more efficient
Now to some pointers on the SCOM configuration (tested on SCOM 2016):
- Script will run on the members of the Notification Resource Pool in SCOM, default is all scom mgmt servers.
- Make sure the execution policy for Powershell is set to a minimum of RemoteSigned for the script to work [Set-ExecutionPolicy -ExecutionPolicy RemoteSigned]
- Make sure the default action account (will be used to execute the script) is local administrator on the scom management server that will run the script.
- Run [New-EventLog -LogName $EventLog -Source $EventSource] on every server that will run the script. Where $EventLog and $EventSource are the variables set in the script, changes these out with the values there. The reason for this command is to allow the script to log to the eventlog during runtime.
- Put the script in c:\scripts on every mgmt server member of the Notification Resource Pool.
- Create a command channel with the following settings:
123456Full path of the command file:c:\windows\system32\windowspowershell\v1.0\powershell.exeCommand line parameters:c:\scripts\Send-PSWinCSMS.ps1 -MessageType 'SMS' -MessageText 'AlertName: $Data[Default='Missing Alert Name']/Context/DataItem/AlertName$%0a$Data[Default='Not Present']/Context/DataItem/AlertDescription$' -SubscriptionID '$MPElement$'Startup:c:\scripts
Note that this will send both alert name and description in the SMS message. Also %0a is used to add a line shift in the message. You can change this to include other content variables that SCOM supports.
- Create a subscriber and add the SMS command channel created above to it.
- Create subscribers that has a phone number set for the Text Message (SMS) channel type
- Create a subscription that contains subscribers with a text message channel type, and the subscriber created above for the SMS command channel. Also add the SMS command channel on the channel tab in the creation wizard.
- Edit the script and add your username and password for the SMS gateway.