There has been a number of questions about the command notification channel in Technet forums. Here is a example how to configure a command notification channel, a subscriber for the channel and a subscription. This example configure a command notification channel to run a vbscript. The vbscript echo a time stamp and the alertname to a local file.

1. Go to Administration/Notification/Channels and create a new command notification channel. For example
Channel name: Contoso Command Notification Channel
Full path of the command file: C:\windows\system32\cmd.exe
Command line paramters: /c C:\logfile.vbs $Data/Context/DataItem/AlertName$
Startup folder for the command line: C:\

2. Go to Subscribers and create a new subscriber
Subscriber name: Contoso Command Line Subscriber (note that you do not need to select a AD user)
Schedule: Always send notification
Addresses: Added a new address
-Address name: Contoso Command Address
-Channel type: Command
-Command Channel: Contoso Command Notification Channel
-Delivery address for the selected channel: I just left this with default, something about sip: but it resultet in a blank field, so just leave it
-Schedule: Always send notification

3. Goto Subscriptions and add a new subscription, for example
Name: Contoso Command Line Subscription
Criteria: with a specific resolution state: new(0) and closed (255)
Subscribers: Contoso Command Line Subscriber
Channel: Contoso Command Notification Channel
Summary: Make sure the channel is enabled

Thats it, and the logfile.vbs looks like:

' ******************************************
' GET PARAMETERS INTO SCRIPT
' ******************************************
strAlert = Wscript.Arguments.Item(0)

‘ ******************************************
‘ LOG TO FILE (DATE,TIME,TO,ALERT NAME,STATE
‘ ******************************************
Dim Stuff, myFSO, WriteStuff, dateStamp
strdateStamp = Date()
strTimeStamp = Time()
‘Write information to Text File
Stuff = strDateStamp & “,” & strTimeStamp & “,” & strAlert
Set myFSO = CreateObject(“Scripting.FileSystemObject”)
Set WriteStuff = myFSO.OpenTextFile(“opsmgr_notification_logfile.txt”, 8, True)
WriteStuff.WriteLine(Stuff)
WriteStuff.Close

More info about command notification channel here.

  1. Hi, thanks for reading my blog. Do you want Ops Mgr to write the alert to a logfile, so it like a logfile for Ops Mgr? That you can do with a subscription, take a look at http://contoso.se/blog/?p=860

  2. Hamendra says:

    Hi Anders,

    does SCOM have capability to write the alerts in logfile? if so can you please let me know the instruction.

    Thanks,
    Hamendra

  3. […] provide a good starting place for this approach to write to a log file via a command channel  (http://contoso.se/blog/?p=860). This approach would be less intensive than the one that I represented but would require manual […]

  4. Hi, take a look at http://technet.microsoft.com/en-us/library/dd440889.aspx , it will show you how to setup notification in Ops Mgr.

  5. Gopal says:

    Hi Anders,
    We have installed trial version of SCOM 2007 monitoring tool for Biztalk. Whenever orchestration suspended, we are getting alert in Ops manager console. But alerts have not been automatically forward to E-mail. Every time we have to manually forward the alert to “E-mail by using Forward to–> operations manager Internal Connector”. Could you please advise how to configure alert being automatically forward to E-mail.
    Please let me know, if you need more clarification.

    Thanks and regards,
    -Gopal

  6. David says:

    Hi,

    I tried your example and it work. But, I would like to get the recipient of the notification.
    I use “$Data/Recipients/To/Address/Address$” and it always content the string “address”.
    Do you know a way to get the recipient or subscriber name?
    or the TO in your vbs comment:
    ‘ LOG TO FILE (DATE,TIME,TO,ALERT NAME,STATE

    any ideas?

  7. Sandy says:

    Yes it does work : I run the following from the command line

    c:\windows\system32\cmd.exe /c c:\smsapp\sendsms.bat ” Test”

    If I create a BAT which starts command shell and from there if I execute the c:\smsapp\sendsms.bat ” Test” , It works too.

  8. If you run the command manually, does it work? Try create a BAT file that will start a commnd prompt, cmd.exe, and then sends the SMS.

  9. Sandy says:

    I do have a batch file which send sms via Gateway. As mentioned in the post I have done the config as below but notification doesnt happen. An ideas?

    Full path of the command line : c:\windows\system32\cmd.exe

    Command line param : /c c:\smsapp\sendsms.cmd “$Data/Context/DataItem/AlertName$”

    Start up folder : C:\smsapp

  10. Viv_Ian says:

    I exactly implemented the same config, it doesnot work.even when I change the command line parameters to something simple as /c ipconfig>c:\test.txt it write a text file,it doesnot work
    However when I manually enter

    C:\windows\system32\cscript.exe /c C:\sms.vbs test

    It works.

    What could be wrong.I am pretty new to SCOM

    Thanks

  11. AnotherITguy says:

    Any idea why I’m getting “Subscript out of range” when I try to run the vbs manually?

  12. Worker says:

    Have some a Idea how yan I open the internet explorer and give the Alert Content to defined places in the URL. I need somthin easy for our Helpdesk to open Tickets for 2nd Level manually but without Mail and any past an copy.

  13. Kenny says:

    Meanwhile I found the problem (but no solution :d). I added some logging into my vbs code. I am using AT commands to send an SMS, more specific the sendkey method. When I ask the vbs to create a txt file after each line of code (example: cmd.txt, telnet.txt, sms.txt), the script creates this txt files.

    However, when you execute manually the VBS file, the focus is within the cmd / telnet session and writes the sended keys. But what happens in SCOM ? Where are the keys send to ? I guess not to the activated cmd/telnet. That’s my problem, now finding the solution …

    Hereby the script I used:

    Set oShell = CreateObject(“WScript.Shell”)
    set WshShell = WScript.CreateObject(“WScript.Shell”)
    oShell.run”cmd.exe”
    WScript.Sleep 500
    oShell.SendKeys”telnet 10.1.1.208 5000″
    oShell.SendKeys(“{Enter}”)
    WScript.Sleep 1000
    oShell.SendKeys”admin”
    oShell.SendKeys(“{Enter}”)
    WScript.Sleep 1000
    oShell.SendKeys”admin”
    oShell.SendKeys(“{Enter}”)
    WScript.Sleep 1000
    oShell.SendKeys”AT”
    oShell.Sendkeys (“{ENTER}”)
    WScript.Sleep 5000
    oshell.SendKeys “AT” & Chr(13)
    WScript.Sleep 10000
    oShell.SendKeys “AT” & (“{+}”) & “CMGS” & (“{=}”) & “+xxxxxxxx”
    WScript.Sleep 10000
    oShell.SendKeys “{Enter}”
    WScript.Sleep 10000
    oShell.SendKeys “test scom”
    WScript.Sleep 10000
    oShell.SendKeys “^(Z)”
    WScript.Sleep 15000
    oShell.run”taskkill /F /IM telnet.exe”
    WScript.Sleep 5000
    Wscript.Quit

  14. try add the cscript.exe as the command starting sms.vbs. You can see in my example how I did with a vbs file from a notification channel.

  15. Kenny says:

    I exactly implemented the same config, when I change the command line parameters to /c ipconfig>c:\test.txt it write a text file, but when I change the command line paramaters to /c C:\sms.vbs it doesn’t do anything at all, however when I manually enter

    C:\windows\system32\cmd.exe /c C:\sms.vbs

    it works … any idea ?

  16. the RMS, and outside of Ops Mgr.

  17. Ed says:

    Where does the executable or script reside? In the RMS or MS or Gateway?

  18. I think you need to use “” around the paramter, for example “$Data/Context/DataItem/AlertDescription$”

  19. Justin says:

    This script works great…except when I run it, it only takes the first word from the Alert?

    It appears as though the following detects a space in the variable…which causes it to only log the single word to the log file…has anybody else seen this behaviour?

    Wscript.Arguments.Item(0)

  20. Anders says:

    You could try C:\windows\system32\cmd.exe as command and then C:\windows\system32\windowspowershell\v1.0\powershell.exe C:\PutScriptMode.ps1 as parameter.

  21. Paul says:

    Hi Anders,

    How can i get this to run a powershell script? I can get your VBscript to run but not powershell.

    i’ve got

    C:\Windows\sytem32\windowspowershell\v1.0\powershell.exe in the full path of command

    then

    C:\PutNodeInPatchMaint.ps1 in the Paramters

    and

    C:\in startup folder but the powershell script never get executed.

    if i run

    C:\Windows\sytem32\windowspowershell\v1.0\powershell.exe c:\PutNodeInPatchMaint.ps1

    the script works so i know the script is ok.

    any ideas?

  22. If anyone is interested, I have a blog enter on how to ‘Forward Ops Mgr Alerts via an SNMP Trap’ via the Command Notification in SP1 & R2.

    http://systemcenterspartan.wordpress.com/2009/06/30/forwarding-opsmgr-alerts-snmp/

    Cheers,
    System Center Spartan