0

Trying to set up a simple two-state script monitor in SCOM 2012 R2 to check for the existence of a particular file on a server. my code is as follows:

$API = new-object -comObject ‘MOM.ScriptAPI’

$Bag = $API.CreatePropertyBag()

$Exists = Test-Path ‘c:\temp\testfile.txt’

if ($Exists)
{
    $Bag.addValue(‘State,’YES’)
}
else
{
    $Bag.addvalue(‘State’,’NO’)
}

$Bag

If I create the monitor and enable it for the given server, it registers and has an initial healthy state. If the result returned is ‘YES’, the state should change to unhealthy. However, if I create the test file, the monitor never changes state. It’s targeted to a Windows 2008 R2 server, and is set to run on a 5 minute interval. If I manually execute the commands in a PS window on the server, it returns the appropriate data. The parameter I’m using to get the results back to the monitor is :

Property[@Name=’State’] equals YES (unhealthy)
or                             NO (healthy)

I know I’m missing something dumb..there’s just not much to this monitor. Any ideas?

TIA.

INDIA IT TECH
  • 1,902
  • 4
  • 12
  • 25

1 Answers1

0

Try to specify datatype in your condition detection, like

          <Expression>
            <SimpleExpression>
              <ValueExpression>
                <XPathQuery Type="String">Property[@Name="State"]</XPathQuery>
              </ValueExpression>
              <Operator>Equal</Operator>
              <ValueExpression>
                <Value Type="String">YES</Value>
              </ValueExpression>
            </SimpleExpression>
          </Expression>