Running Rule based on PS script from SCOM, and implementing the result to PropertyBag

Hi everyone!

I would like to know how to properly create a PowerShell-based Rule that will collect a message send count from my Edge Exchange servers in my environment.
I am already using SCOM + SquaredUp to gather a huge amount of data from the whole infrastructure with like 500~ VMs.
Unfortunately, the Microsoft MPs don’t include such things, like messages send count in exchange servers. Therefore I am here to ask how properly use Powershell Authoring MP from cookdown, and make my life easier.

Firstly I tried some totally basic things, but I am not sure what am I missing with that configuration.

I did create, a Powershell-based rule on a Powershell Authoring MP, and assigned it to the Group with only one VM. (The group that I made before).

My script:
param([string]$Arguments)

$ScomAPI = New-Object -comObject “MOM.ScriptAPI”
$Processes = (Get-process).count
$PropertyBag = $ScomAPI.CreatePropertyBag()
$PropertyBag.AddValue(“Proces”,[string]$Processes)

$PropertyBag

Performance Mapper:

Object:
ProcessesRDP
Counter:ProcessesNumber
Instance:
Blank
Value
$Data/Property[@Name=‘Proces’]$

As you can see, I just want to test things out and implement the result to my monitoring as a new value in Performance Viewer.
The schedule is set to “Run every: 5 Minutes”.

I am not sure if everything is set properly, but the result is… Well, I can only say that it isn’t working.
How do I even know if the SCOM does something with that rule?
Should I browse EventViewer on a Vm and check if PowerShell script event started?

So you see… I came here to learn how to use the Powershell Authoring MP properly.
I would like to know how to set a super easy script and implement the result to SCOM property bag.

Any suggestions would be great! :slight_smile:

Ok, so basically I got this thing working.

But still, I don’t know where to search for some EventLogs. Should I look for them in SCOM EventViewer or VM that I target with my Rule?

Also, does anyone know if it is possible to implement something like import-module while applying the script on the target machine?
If I understand correctly SCOM with the Rule based on Powershell MP runs scripts on the target VM with the VMs PowerShell. Is that correct? Or is it just SCOM that runs scripts with Its own PowerShell?
So if I want to use ExchangeShell for like message tracking I first need to Import-Module or Add-PSSnapin. Is it possible?

For example:

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

Will that work?

Hi Mateusz,

Welcome to the community!

In general what the rule is targeted at defines where the rule is run (and where events are located). If you’re targeting a group you may find that the rule is run on a management server rather than the members of the group (the management server looks after the group).

Typically if you are logging an event in a PowerShell script (eg using the logscriptevent method on the API) you’ll want to look in the Operations Manager event log on the machine that is running the workflow:

image

For debugging PowerShell I absolutely love transcript logging (and rave about it like a lunatic).

In my experience, there’s no real issue pulling in modules (as long as they are in an accessible scope). Snapins are old and weird but behave quite similarly to modules so I can’t foresee any immediate issues with them, but I’ve never tried.

The other issue you may have is the agent account. Generally (but not always) this defaults to the local system account. If that doesn’t have access to what you are trying to pull in you may need to look into run-as accounts to use to connect to your source. A quick and dirty workaround I’ve used in the past is to use a scheduled task to dump the required info to a CSV/XML file which can then be picked up by your rule.

Longer-term it might be worth looking at authoring, which will allow you to do a lot more with a bit of work. Channel 9 (R.I.P) used to have a great course on management pack authoring that went into some of this in more detail. Through The Wayback Machine it might be possible to get at the lessons still. Unfortunately, I don’t know of anywhere else currently that the content might be hosted.

Failing that MP University and SCOMathon both have some pretty decent sessions on authoring if you look through the past sessions. Kevin Holman has also partnered with MP University to produce a whole bunch of content that can be found on his blog.

Are you looking for the Exchange mail queue performance counters? They are definitely collected within the Exchange management pack.

1 Like

Thanks for your answers.
I managed to find a workaround by using invoke-command to get the results from my Exchange server. I use Get-Messagetrackinglog and pass results into a variable and after that to $propertybag. For now, I can see the result in SCOM server, but I am curious how to use that custom object in SquaredUp graph.

I can’t seem to find “metric” with a custom object from the rule.
Should I set the Scope option to Exchange Server directly or use the group that contains the Exchange server and is used in the rule? Or is it something else?

If I set the scope to my server, for example, ExchangeServer I can only see the metrics that are implemented with official MP I believe. The same goes for the group.

Is it because the object is a bit different than the other?

If it’s running against the group, you’ll probably find the metrics attached to the group in SquaredUp. Maybe. This isn’t really good practice so I’m not sure. SquaredUp often digs into the objects in a group rather than the group itself as that is usually what you want, but likely isn’t the case in this example. Generally (but not always) targeting rules and similar workflows at a group is bad. Overrides and the like, sure, but workflows not so much… Invoke-Command implies to me that one of the management servers is doing the lifting here rather than the server itself.

Before jumping into SquaredUp and how to get at that metric, I’d go and double-check JohnnyK’s post to make sure that there isn’t a rule that you can’t easily enable to grab what you’re looking for (I haven’t used the Exchange MPs in years). Next, I’d take a look at the targeting. Kevin Holman (as always) has a great blog post on creating a simple class, based on servers here. Otherwise I’d take a look at his ‘ugly’ route and target the rule at the Exchange server class in the disabled state and enable it for your group - It will definitely be quicker as you already have all the components in place. That way you’re running the rule at the expected target and, in theory, the SquaredUp graphs work as expected.

Long-term, I would say try to get a nice tight class for your edge servers (if one doesn’t already exist) and target that as everything should just fall into place nicely. It’s jumping in a bit but the management pack authoring course does cover discoveries quite nicely.

So in the short term, I think you need to change the target of the rule to a class related to exchange that makes sense, make sure the rule isn’t enabled by default, and then override the rule so that it is enabled for that group.

Outbound mail queues are picked up by the Exchange MP and collects Transport, Submissions, Delivery Smtp send etc. SquaredUp will display this better than the SCOM console even by scoping to the Windows computer object just by searching.
image

Also, if the MP isn’t recording a queue you need then I’d use write a collection rule using the authoring wizard and selecting the perfmon counters in the traditional way from the Exchange server.
image

Just to be clear.
I need to get information on how many e-mails does exchange server send since midnight.
image
I need output of sendexternal eventid.
I am not sure if Exchange MP does that. That is why I create the custom Rule with PowerShell script that invoke-command with -scriptblock {Get-MessageTrackingLog -EventId sendexternal… (and other things)}.

Invoke-Command -Session $ExchangeServer -ScriptBlock {(Get-MessageTrackingLog -start “00:00:00” -EventId sendexternal -ResultSize unlimited).count}
That is what I am using right now, and it is working fine.
I got the data in SCOM.

For now, it is working from midnight to noon, and from noon to midnight. Just need to fix the command and properly set the time after “-start” to make it works with 24h data.

My point here is how to get that Custom output to SquaredUp.


performance view

In SquaredUp. I set the scope to that target group which Exchange Server is part of and can’t find the metric from custom Rule. In scope, the group name loads from the “popup” menu while typing the name, so I assume that everything is working and SquaredUp gets data from SCOM. At least my custom group name.

Here is what I see while setting “metric”. There are a bunch of “options”, but none of them is what I need. Is it because SquaredUp can’t load that kind of data from SCOM, or there is some sort of problem with “workflows”?

OK this bit here:
image
This isn’t normal.

Think of it this way. Does your group send the emails or the Exchange Servers in the group? You don’t normally target a group like this, you normally target a specific class such as Exchange Server. The group is just there to make organisation easier.

A group is just an object with an abundance of containment relationships. If you think about the relationship between a server and a disk, you have a very similar relationship between a group and the things inside the group.
It’s not quite the same, but If you have a metric that you wanted to collect from the disk you’d probably expect it to be on the disk itself rather than the server that has the disk in it.

In your situation, the things inside your group are probably somewhat irrelevant.

This bit here:


Says that you want the things contained in the group (which is normal). So you won’t see the metric there because they don’t collect this metric. The group does. If you use list or advanced you can probably get at the metric, but I’m not sure…
The problem with the workflow is that it’s not targeted normally.

The only analogy I can think of is AD and Group policy:
You can apply a GPO to an OU and then use a group to define the scope of how widely it’s applied.

My point here is how to get that Custom output to SquaredUp.

If you get the targeting of your rule right, SquaredUp will just know about it like it does everything else.

Target the Exchange Server class.
Leave the rule disabled by default.
Use an override to turn it on for the group.
Make it work without Invoke-Command and you’re probably on the right path.

Thanks for your answer!
Thanks for being so patient with me. I am still learning how do these things work in SCOM.

Could you please explain what do you mean by:
“Leave the rule disabled by default”
“Use an override to turn it on for the group.”?

image


Is that correct? If so, it is not working for some reason, or I am not aware of where to look for output.
If Rule is enabled by default then everything is working, and I can get output on performance view under the MP that depends on PowerShell Authoring MP

Also, what do you exactly mean by “Exchange Server class”, especially “class”. Maybe I still don’t understand that correctly. :sweat_smile:

Ok, I finally got it right!

I got my data on SquaredUp. Thanks for your time, and help :).

One more thing that interests me now is if everything is set properly, should I be able to set “metrics” of data from the “popup menu”, while typing? It didn’t work for me. I can’t find the data that is in SCOM. Luckily I managed to work around that by choosing “Advanced” and specifying parameters manually.

Also is it possible to set the custom metric label to not round off the value? I mean if for example, I have output in SCOM for my DATA like 104533, in SquaredUp shows as 104K. And that is all. Is there any way to get full output in SquaredUP?

1 Like

Good to hear that you cracked it! :slight_smile:

In my experience, yes you should just be able to use the popup menu to pull back the metric names, but I’m not sure how that works underneath. Might be some caching in play or something like that that needs to work itself through?

It depends on where you want the label. Their support site here goes into more details, but loosely if you want that in the tile you can, but if you click into the tile for details you can’t (at the time of writing).

1 Like