In September of 2010 Tao Yang wrote a fantastic Powershell script (v2.0 here) for command channel notifications in System Center Operations Manager. Here is my adaptation of the script.
NOTE: I've tested this thoroughly in my lab and I suggest you do the same before using in any other environments. This script is meant to be an example and therefore use it at your own risk.
Download latest version here: Technet Gallery
From: SCOM-Alert [mailto:NOREPLY@contoso.com] Sent: Thursday, May 14, 2015 10:53 AM To: Tyson Paul Subject: New, MyDev:MS02\http://paypal.com, HTTP Request Error: ErrorCode Exceeded Threshold
Severity: Critical Error
ErrorCode Exceeded Threshold ErrorCode: 2147954402 Monitor Settings: URL: http://paypal.com GroupID: URLGenie_Default DNSResolutionTime: 0 RetryCount: 1 Wiki: No link provided Description: URL address to monitor. ******* Request Headers ******* GET / HTTP/1.1 User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT; Windows NT 6.1; en-US) Content-Type: text/xml;charset=utf-8 Accept-Language: en-US Accept-Charset: utf-8 From: SCOM@yourdomain.com Connection: Keep-Alive ******* End Request Headers ******* ******* Response Headers ******* ResponseHeaders: ******* End Response Headers *******
HTTP Request Error: ErrorCode Exceeded Threshold
Alert Resolution State:
Alert Monitor Name:
URLGenie Error Code Monitor
Alert Monitor Description:
5/14/2015 10:52:40 AM
Operations Console Login Info
ADMIN DIAGNOSTIC INFO
**Use this command to view the full details of this alert in SCOM Powershell console:
Get-SCOMalert -Id "caa328ed-5375-4e00-9340-b0684ace4795" | format-list *
This email sent from:
CF2: Alert.NetBIOSDomain Name:
CF5: Management Pack Name:
URLGenie Management Pack
CF6: Alert Class Name:
CF8: Workflow Type
CF10: Helpful POSH Command
Get-SCOMAlert -ID "caa328ed-5375-4e00-9340-b0684ace4795" | format-list *
Context: Note: This context data is only relevant to the moment/time at which this alert was sent.
type : Microsoft.SystemCenter.WebApplication.WebAp plicationData time : 2015-05-14T10:52:21.0024526-07:00 sourceHealthServiceId : 120875E8-C79E-91CA-E3AC-EA09A391F4BD RequestResults : RequestResults TransactionResponseTime : 19.0355422 TransactionResponseTimeEvalResult : 0 CollectPerformanceData : CollectPerformanceData
No resolutions were found for this alert.
The context information provided in this notification is limited and is not always helpful. To see more detailed information about this alert, log into the appropriate SCOM console for the applicable datacenter (SCOM management group) and use the Health Explorer to find more details about the state change event for the object.
From: SCOM-Alert [mailto:NOREPLY@contoso.com] Sent: Thursday, May 14, 2015 11:14 AM To: Tyson Paul Subject: Closed, MyDev:MS02\http://paypal.com, HTTP Request Error: ErrorCode Exceeded Threshold
type : Microsoft.SystemCenter.WebApplication.WebAp plicationData time : 2015-05-14T11:02:21.0024294-07:00 sourceHealthServiceId : 120875E8-C79E-91CA-E3AC-EA09A391F4BD RequestResults : RequestResults TransactionResponseTime : 1.4710738 TransactionResponseTimeEvalResult : 0 CollectPerformanceData : CollectPerformanceData
In the script there are instructions at the top that describe a few of the settings (lines of code) that must be configured before use. Simply edit the "Settings" area within the script. Use Notepad or your favorite text editor. I like Powershell ISE or Notepad++ . Configuration is very simple and there are examples for each setting within the script comments at the top.
Remove all management servers from your Notifications Resource Pool except for one single server. This will help you troubleshoot during testing if needed.
Create this folder on your test mgmt server: "C:\SCOM_SCRIPTS\Notifications"
Put the script into that new folder.
Open the script and customize the necessary variables: smtp server, port, smtp sender, web console url, etc. See help notes at top of script.
Make sure that your default action account is a local administrator on your test mgmt server.
Make sure that your Powershell execution policy is not blocking the command channel execution.
Create the command channel:
New! Added support for schedules on Subscriber and individual Addresses.
Note: ANY Exclusions will take precedence over any Inclusions.
If the script doesn't appear to be running, open Task Manager, sort by Name, and watch for a new Powershell.exe process to spin up under the Default Action Account context/user . The script takes from 10-20 seconds to complete. If the new Powershell.exe process doesn't open within 60 seconds or opens briefly and then disappears, you have a problem.
Make sure the script itself is not being blocked from running. Right-click the script, select Properties. If you see a "Unblock" button, click it to make sure the script is not being blocked from execution.
The Powershell execution policy may be Restricted. Change this to Unrestricted.
There may be an error with the Channel configuration or path(s). Double check the path to the .ps1 script. Make sure the full file path is precise. I suggest navigating to the actual path where the script lives and copying the full path right from the File Explorer address/path field. This way there's no chance of misspelling the path to the script. See command line parameter field example above.
Check the Notifications folder for any errors that might appear in the error log. Use the -Verbose and -WriteToEventLog command line parameter switches for additional Ops Manager event logging detail.
If needed, you can manually run the script. You must first set the required variables near the top of the script.
############################## UNCOMMENT FOR MANUAL TESTING ######### $Description = "MyDescription"# $alertID=''# $SubscriptionID=''# $ErrorLogFile='C:\SCOM_SCRIPTS\Notifications\ErrorLogFile.txt'# $Verbose = $true############################## FOR TESTING #############################
An additional method to gain visibility into any errors that might occur (before the script has a chance to write error output to the event log) is to append the line shown directly below at the end of the command line parameters:
; Write-Output "$($Error)" | Out-File -Filepath C:\SCOM_SCRIPTS\Notification_Errors.txt
"C:\SCOM_SCRIPTS\Notifications\SCOMEnhancedEmailNotification.ps1" -Description "MyDev" -alertID '$Data/Context/DataItem/AlertId$' -SubscriptionID '$MPElement$' -ErrorLogFile "C:\SCOM_SCRIPTS\Errors.log" -Verbose -WriteToEventLog ; Write-Output "$($Error)" | Out-File -Filepath C:\SCOM_SCRIPTS\Notification_Errors.txt
This will output any errors that occur when the workflow attempts to launch the command channel.
Also, I've seen some weird things happen when copying/pasting from online sources into Powershell scripts. Make sure you are not copying some weirdly encoded characters. I'm pretty sure this blog doesn't use any strange encoding but to keep your sanity, copy the code portions into Notepad++ and force the encoding to be UTF-8, then copy from there into the Console wizard.
*Please let me know if you have any suggestions to improve this article.
Disclaimer: Sample scripts in this guide are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.