How to Configure Command Notification in SCOM 2012 with PowerShell script.
Here’s a step by step tutorial how to create a Command Notification which calls a PowerShell script. The step by step is in SCOM 2012, but can also be used in SCOM 2007 R2.
Step 1 Create PowerShell script
Create the following script and test:
Param ([ String ] $AlertName ,[ String ] $SubscriptionID )
$Logstring = $AlertName + " " + $SubscriptionID
$Logfile = "c:\temp\LogAlerts.log"
$DateTime = Get-Date - Uformat "%y-%m-%d %H:%M:%S"
$Logstring = $DateTime + " " + $Logstring
Add-content $Logfile - value $Logstring
I have the script named and located here:
And you can test it with:
Step 2 Create Channel
Go to Administration -> Notifications -> Channels and create new command channel:
With the following parameters:
Channel name: Contoso PowerShell Command Notification Channel
Full path of the command file: c:\windows\system32\windowspowershell\v1.0\powershell.exe
Command line parameters: "c:\temp\LogAlerts.ps1" '$Data/Context/DataItem/AlertName$' '$MPElement$'
Startup folder for the command line: c:\windows\system32\windowspowershell\v1.0\
Save and finish:
As a result:
Step 3 Create Subscriber
In subscribers you define who or what will receive the notifications. Go to Subscribers and create a new subscriber
And add the following parameters
Subscriber name: Contoso Powershell Command Line Subscriber
Schedule: Always send notifications
In addresses click Add to add the channel you want to post the notifications
…and fill-in
Address name: Contoso Powershell Command Address
In Channel
Channel Type: Command
Command Channel: Contoso Powershell Command Notification Channel
In Schedule choose: Always send notifications
And click Finish. Now the subscriber is configured. Click Finish again:
The subscriber is send ready:
Step 4 Create Subscription
Here you configure which alerts go to which subscribers using what channel. Start here:
And add the following parameters:
Name: Contoso Powershell Command Line Subscription
Criteria: Notify on all alerts
In subscribers choose Add…
Choose the Contoso Powershell Command Line Subscriber
Click OK to add it here:
Choose the channel where you want to the notification to go to by choosing Add…
Add the PowerShell channel:
And add it by clicking OK:
Check the summary:
And if OK click Finish.
Step 5 - Check if the notification is working
Check if the notification is downloaded:
And if already active:
Create an alert (I created test alert for this):
See if the alert is raised:
If all configured well then you see here:
Additional information about command channel can be found here:
How to Enable a Command Notification Channel (SCOM 2012)
https://technet.microsoft.com/en-us/library/hh212711.aspx
Enable a command notification channel (SCOM2007)
https://technet.microsoft.com/en-us/library/dd440871.aspx
Configure Command Notification in R2
https://contoso.se/blog/?p=860
Alert notification troubleshooting in System Center Operations Manager 2007
https://blogs.technet.com/b/operationsmgr/archive/2010/08/11/alert-notification-troubleshooting-in-system-center-operations-manager-2007.aspx
Account for Command Channel when using Notification in OpsMgr 2007 R2
https://blog.coretech.dk/kra/account-for-command-channel-when-using-notification-in-opsmgr-2007-r2/
Author: Dirk van Coeverden