Powershell Performance Rule

Hi all,

Having difficulty collecting daily counts of discovered SCOM Classes etc split by Operating Server amount etc, not sure if anyone has managed to do this.

My SCOM result is coming back a return value of 0 instead of the actual figure, outside of SCOM this works.

The performance rule is as followed:


import-module OperationsManager

$ScomAPI = New-Object -comObject “MOM.ScriptAPI”

$Instances = @(“Microsoft.Windows.Server.Computer”, “Microsoft.Windows.Server.2008.Computer”)

Foreach ($Instance in $Instances)


$query = (Get-SCOMClass –name $instance | Get-SCOMClassInstance | Select Path)


$PropertyBag = $ScomAPI.CreatePropertyBag()




Send output to SCOM



This is targeted to All Management Servers Resource Pool, and the performance counters are:
Instance = $Data/Property[@Name=‘Instance’]$

Value = $Data/Property[@Name=‘Metric’]$


Thanks in advance.

I did try a single instance originally and it was still returning as 0. Thanks

I am not absolutely sure but I think the problem is that your script returns a lot of property bags instead of one. Try to close the foreach loop before submitting the propertybag to the SCOM channel. This would also explain why your script works outside of SCOM because you did not use the propertybag.

Hope this helps

Does this work if you have two separate rules, rather than having a foreach?