Command Line Parameters for SCOM Command Notification Channel

Written by Tao Yang

Few years ago, I wrote the Enhanced SCOM Alert Notification script and I blogged it here.

In all the environments that I implemented this script in command notification channel, there were always some random alerts not been processed.

Few months ago, I was working on another PowerShell script to be used in command notification channel to update a custom field when alerts are created. While I was testing it, I found it has exactly the same problem, the subscription randomly skips alerts and left them not processed.

In the end, I found the cause of the problem: the command line parameters are not configured properly! The details can be found in Steve Rachui’s blog article here: Updating custom alert fields using subscriptions and powershell. Steve explained in the article:

There are several quotation marks in the command line so I’ve listed the text again below in case you want to copy/paste in your environment. Note the highlights above – these are single quotes that go around alert ID as it’s passed to the script. Make sure you include these because if you don’t the alert ID won’t be handled correctly in all cases and the script will not run consistently.

Full path of the command file: c:\windows\system32\windowspowershell\v1.0\powershell.exe
Command line parameters: -Command “& ‘”C:\alertupdater.ps1″‘” ‘$Data/Context/DataItem/AlertId$’
Startup folder for the command line: c:\windows\system32\windowspowershell\v1.0\

So to fix my problem with my Ehanced SCOM Alert Nofication Script, the command line parameter should be:

-Command “& ‘”D:\Scripts\SCOMEnhancedEmailNotification.ps1″‘” -alertID ‘$Data/Context/DataItem/AlertId$’ -Recipients @(‘Tao Yang;Tao.Yang@xxxx.com’,John Smith;John.Smith@xxxx.com‘)

I’ve updated the original Enhanced SCOM Alerts Notification EMails blog article to reflect this change.

5 comments on “Command Line Parameters for SCOM Command Notification Channel

  1. Pingback: ENHANCED SCOM Alerts Notification Emails! | Tao Yang's System Management Blog

  2. Hi tao yang,

    what is the power shell command to view the criteria description details of Subcriptions on SCOM r2? One of the subscription is corrupted and i cannot view it in GUI console.

    i used the below command
    get-notificationsubscription | format-list DisplayName,@{Label=”Criteria”;Expression={$_.configuration.Criteria}}

    however it just gives expression details only

    Many Thanks
    David

  3. How can I get this to work when I have IP Address for name and reading from a text file?

    Thanks

  4. Hopefully you are still viewing this posting: I have setup the script and getting errors. Please reply to dabowitt@ddn.com if possible. Thanks

    alert.NetBiosComputername:
    alert.PrincipalName:

    Class.name:

    TempFilePath: C:\Users\xxx@\AppData\Local\Temp\tmp3712.tmp

    Mailmessage: System.Net.Mail.MailMessage
    Exception calling “Send” with “1” argument(s): “Failure sending mail.” You cannot call a method on a null-valued expression. You cannot call a method on a null-valued expression. You cannot call a method on a null-valued expression. Property ‘CustomField10’ cannot be found on this object; make sure it exists and is settable. You cannot call a method on a null-valued expression. Cannot validate argument on parameter ‘Class’. The argument is null or empty. Supply an argument that is not null or empty and then try the command again. Property ‘CustomField9’ cannot be found on this object; make sure it exists and is settable. Property ‘CustomField8’ cannot be found on this object; make sure it exists and is settable. Property ‘CustomField7’ cannot be found on this object; make sure it exists and is settable. Property ‘CUstomField6’ cannot be found on this object; make sure it exists and is settable. Cannot validate argument on parameter ‘DisplayName’. The argument is null or empty. Supply an argument that is not null or empty and then try the command again. Cannot bind argument to parameter ‘Id’ because it is null. Property ‘CustomField3’ cannot be found on this object; make sure it exists and is settable. Property ‘CustomField2’ cannot be found on this object; make sure it exists and is settable. Property ‘CustomField1’ cannot be found on this object; make sure it exists and is settable. You cannot call a method on a null-valued expression. You cannot call a method on a null-valued expression. You cannot call a method on a null-valued expression. You cannot call a method on a null-valued expression. You cannot call a method on a null-valued expression. You cannot call a method on a null-valued expression. You cannot call a method on a null-valued expression. Cannot validate argument on parameter ‘Id’. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.

    My command line argument is:
    -Command “& ‘”C:\Scripts\SCOMEnhancedEmailNotification_v2.2.3.ps1″‘” -alertID ‘$Data/Context/DataItem/AlertId$’ -Recipients @(‘Username;USERNAME@xxx.com’)

    startup folder: C:\Scripts

    My only changes to the script is:

    # Other Settings:
    # SMTPServer
    $SMTPServer = “servername.domain.com”

    # iPort
    $iPort = 25

    # SMTPSender – SMTP Sender (return address)
    $SMTPSender = New-Object System.Net.Mail.MailAddress(“name@xxx.com”, “SCOM-Alert”)

    # WebConsoleBaseURL – Web Console URL, same as what is configured in the SCOM Console.
    # CompanyWikiURL – Your wiki site or knowledge base. If you don’t have a wiki, just set this to the same as the WebConsoleBaseURL
    # ErrRecipients – ist of addresses separated by semicolon. If the script encounters an error, an attempt
    # will be made to send error report to these recipients.
    $ErrRecipients = “name@xxx.com”

  5. Tao great script. I’m running Ops Mgr 2012 R2 and I am having difficulty getting messages sent. Can you please take a look at my command line parameters below and let me know where I am going wrong please.

    Full Path – %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe

    Command line parameters – -Command “&'”C:\SCOM_SCRIPTS\Notifications\SCOMEnhancedEmailNotification.ps1″‘” -alertID ‘$Data/Context/DataItem/AlertId$’ -Recipients @(‘Name;name@fqdn’) -SubscriptionID ‘$MPElement$’

    Startup – C:\SCOM_SCRIPTS\Notifications

    Greatly appreciate any help.

Leave a Reply