SCOM 2012: A 2 State Powershell Monitor that pings an array of computers

Forum: Operations Manager4
Viewing 4 posts - 1 through 4 (of 4 total)
  • #230359
    Profile photo of kapildham

    Hello, an odd request here. Trying to put together a 2 state PS monitor where we have an array of computers that will be piped to Test-connection comandlet within a PS script. If server name is not pingable, adds that to a property bag and we can then play with the Alert text to gereate a meaningful alert.

    The code is below, but somehow I think I am missing something elementary. Another hundred pair of eyes or so won’t hurt so thought of asking for a checkup here:


    Import-Module OperationsManager

    $API = new-object -comObject “MOM.ScriptAPI”

    $bag = $api.CreatePropertyBag()

    $MyArray = @(“server1″,”Server2”)

    $testConnection = test-Connection -computername $MyArray -count 2 -Quiet

    if ($testConnection.Time -ge 30)

    foreach ($Computername in $testConnection)
    {$ServerList= $ServerList + “n” + $($}
    $bag.AddValue(“Server Unreachable”,”$serverList”) #add the list of server to the bag as one property



    Your help will be appreciated.

    Profile photo of Michiel Wouters
    Michiel Wouters

    The elementary thing your missing here, is that you should not use these type of workloads on workflows like this.

    A 2-state-monitor is designed to indicate an operational status of one managed entity. In this case you would target this monitor to a class which functions as a sort of polling/ping/watcher machine. Then still using a monitor is not really the way to go (monitor state changes over and over). You’d better use a rule to launch the script.

    The script itself does not work properly. First create a version using the SCOM ScriptApi to see if it does what you want.

    The code which you show here, does not work:

    • When using -Quiet in Test-Connection, the result is a boolean type
    • When omitting -Quiet, the result is a ping item, on which the property ‘Time’ you use, does not exist.
    • You can’t add the same property to a propertybag (‘State’)

    If you want to know the results of you pinged computers, you should not use -Quiet, and then enumerate the results to see what is the ResultCode or ResponseTime.



    Profile photo of Scott Moss
    Scott Moss

    Try using the PING mp, it will be much better in the long run.

    Profile photo of kapildham

    Thank you so much guys for your help.  This helped me scarp the path I was intending to take.

    Michiel Wouters,  Thank you for the insight. You are spot on for the Boolian type return and time.

    Scott Moss Ping MP was another option I am gonna try, thanks for the advice .

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.