SCOM 2012 Powershell 2 State monitor to ping an array of computers

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)

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

$bag.addvalue("State","bad")
}

else {$bag.addvalue("State","good")
}
$bag
$API.Return($BAG)
"
n”

Your help will be appreciated.

2 thoughts on “SCOM 2012 Powershell 2 State monitor to ping an array of computers

  1. Profile photo of kapildhamkapildham Post author

    Strange, I posted it in the Operations manager Forum. Couldn’t find one with Topic classification as SCOM 2012 while posting it.

    Can I remediate that?

Leave a Reply