Partager via


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:

clip_image001

And you can test it with:

clip_image002

 

Step 2 Create Channel

Go to Administration -> Notifications -> Channels and create new command channel:

clip_image004

 

With the following parameters:

Channel name: Contoso PowerShell Command Notification Channel

clip_image006

 

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\

clip_image008

 

Save and finish:

clip_image010

 

As a result:

clip_image012

 

 

Step 3 Create Subscriber

In subscribers you define who or what will receive the notifications. Go to Subscribers and create a new subscriber

clip_image014

And add the following parameters

Subscriber name: Contoso Powershell Command Line Subscriber

clip_image016

Schedule: Always send notifications

clip_image018

In addresses click Add to add the channel you want to post the notifications

clip_image020

…and fill-in

Address name: Contoso Powershell Command Address

clip_image022

 

In Channel

Channel Type: Command

Command Channel: Contoso Powershell Command Notification Channel

clip_image024

In Schedule choose: Always send notifications

clip_image026

And click Finish. Now the subscriber is configured. Click Finish again:

clip_image028

The subscriber is send ready:

clip_image030

 

 

Step 4 Create Subscription

Here you configure which alerts go to which subscribers using what channel. Start here:

clip_image032

And add the following parameters:

Name: Contoso Powershell Command Line Subscription

clip_image034

Criteria: Notify on all alerts

clip_image036

In subscribers choose Add…

clip_image038

Choose the Contoso Powershell Command Line Subscriber

clip_image039

Click OK to add it here:

clip_image041

Choose the channel where you want to the notification to go to by choosing Add…

clip_image043

Add the PowerShell channel:

clip_image044

And add it by clicking OK:

clip_image046

Check the summary:

clip_image048

And if OK click Finish.

clip_image050

 

 

Step 5 - Check if the notification is working

Check if the notification is downloaded:

clip_image051

And if already active:

clip_image053

Create an alert (I created test alert for this):

clip_image055

See if the alert is raised:

clip_image057

If all configured well then you see here:

clip_image059

 

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

Comments

  • Anonymous
    January 01, 2003
    Hi Fesiro, Thanks for the article. It is very helpful. I am a newbie to SvcMgr and OpsMgr and I am trying to do the following and would appreciate any help. The following is what I am trying to do:
  1. Monitor Servers using SCOM
  2. When one of the monitored server's HDD has a pre-determined amount of disk space left or a service that has stopped, raise an alert in SCOM.
  3. With that alert, raise an incident in SvcMgr.
  4. Using Orchestrator, remediate the issue and change the alert status in SvcMgr. I believe the following is the approach I need to achieve this:
  5. SCOM monitors the servers and raises the alerts
  6. Using the diagnostic and recovery task in SCOM, the service gets restarted / the file gets deleted the PS produces the customised resolution state of that alert
  7. Modify the incidence list is SM that whenever that particular type of incidence comes in to from SCOM, it gets marked in a particular way
  8. Once the specific incidence is created in SM, the orchestrator runbook is triggered and it goes and marks it as resolved. I have a question to ask in regards to this. I believe I can create a command channel to change the nature of the alert in SCOM. Say for example I want to rename all critical alerts coming from a particular server for disk space/service stopping, I want to change all critical alerts to say "Assign to SvcMgr". Is there a way I can achieve that? I am really a newbie and have not got a lot of experience with powershell. Would you be able to direct me towards anything similar? Any help will be greatly appreciated. Thanks in advance.
  • Anonymous
    January 01, 2003
    Hi - thanks for that - perfectly described how to do it!

  • Anonymous
    January 01, 2003
    Hi Fesiro I also forgot to mention that I have created a custom alert state in SCOM in Administration-->Alerts-->New with an ID of 19. Ideally I would want to convert all the new alerts of the type that I want into alerts of this type.

  • Anonymous
    May 08, 2013
    Dirk: Can we add additional fields of information to the log?  Like, Resolution State?  Recipients who have received this notification?  That would make this very valuable as an auditing point.  Where and How can we add additional fields?  I am at a loss as to how SCOM 2012 pulls SMTP outgoing mail for notifications and there is now internal log (within SCOM) to verify who has received notifications.  Thanks in advance.

  • Anonymous
    June 17, 2013
    The comment has been removed

  • Anonymous
    July 22, 2013
    I have been trying to raise notification via Command channel using powershell script in SCOM 2012 we currently have this working in SCOM2007 at the moment a simple script get-date >> C:TempSimpleTest.txt will run interactively on my servers  but once I feed it in to command notification channel fails with not trace in the logs I see the script launch by Opsmgr but not complete , nor record of its failure ?

  • Anonymous
    August 07, 2013
    be carefull you are unable to run any scruipt until you enable them in powershell. try this: Set-ExecutionPolicy remotesigned

  • Anonymous
    March 17, 2014
    Do you perhaps have a script to send out sms's with a modem?