SCOM Powershell Monitor

Hi Team!

I am trying to create a Powershell Monitor on SCOM that counts that Exchange Message Queue and basically generate an alert if it exceeds a certain threshold count. The problem is that it does not work and I am unable to create a health verdict out of it. I have tested the script and it does work but when I include the SCOM objects, it doesnt seem to work. Here is the snippet of the PS I have created:

===

$ScomAPI = New-Object -comObject “MOM.ScriptAPI”
$PropertyBag = $ScomAPI.CreatePropertyBag()
$state = “Unknown”
$queue = 0

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;

$queue = ((Get-Queue | Select-Object @{n=“MessageCount”;e={int}}).MessageCount | measure-object -sum).sum

if($queue -gt 100) {
$state=“OverThreshold”
}
else
{
$state=“UnderThreshold”
}

$PropertyBag.AddValue(“Length”,$queue)
$PropertyBag.AddValue(“State”,”$state”)

Send output to SCOM

$PropertyBag

Am I missing something? I have been trying to make it work for the last couple of hours and I’m not sure what I am doing wrong.

When you say it doesn’t work, which part do you mean? Does the script fail when the SCOM bits are in it or does the monitor that uses the script not change its health state?

If your issue is the second one (the monitor health state never changes), how are you calling the values for the health expressions? I have had issues when setting and retrieving property bag values if double quotes are not used in both places. For example, if your health condition in the monitor is Property[@Name=‘State’], try changing it to Property[@Name=“State”].

I have seen quite a few blog posts and walkthroughs that use double quotes in the script and single quotes in the health expression (or the other way around) but doing that has never worked for me. Double quotes in both has never given me trouble.

How are you handling the authentication to Exchange? Are you using a runas account with your monitor?

The MS Exchange MP has monitors for the queues that you can adjust thresholds on. The only one that doesn’t is the journal queue I believe.