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 current version from Technet here: Download
From: SCOM-Alert [mailto:NOREPLY@contoso.com] Sent: Thursday, October 8, 2015 10:49 AMTo: Tyson Paul <Tyson@contoso.com>Subject: New, TEST:MS02\http://gunbot.net/ammo/rimfire/22short/, HTTP Request Error: Content Validation Error
Severity: Critical Error
The context information for these alerts is not always helpful. To see more detailed information about this alert log into the console for the management group.
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 SCOM management group and use the Health Explorer to find more details about the state change event(s) for the object.
From: SCOM-Alert [mailto:NOREPLY@contoso.com] Sent: Thursday, October 8, 2015 3:32 PMTo: Tyson Paul <Tyson@contoso.com>Subject: Closed, TEST:MS02\http://gunbot.net/ammo/rimfire/22short/, HTTP Request Error: Content Validation Error
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 Config.xml file and customize the necessary fields: smtp server, port, smtp sender, web console url, etc. See the example files also in the folder. This Config.xml file must be located in the same directory as the .SCOMEnhancedEmailNotification.ps1 script. I suggest you put these files in this path on your management servers: C:\SCOM_SCRIPTS\Notifications
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 Management Server 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, then 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. Set-ExecutionPolicy 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 = "ManualTest" # $alertID = (Get-SCOMAlert).ID.Guid # Create a test subscription with "Synthetic" in the name # $SubscriptionID = (Get-SCOMNotificationSubscription -DisplayName *Synthetic* ).ID.Guid # $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.