PowerShell MP | Gather Process Performance Data

Hi Guys,

I have a challnege to monitor the Memroy and CPU utilization of all running processes on 2x Systems…
The option I am currently looking at is to levearge the PowerShell MP and get the data (This is easy enough), but I am not quite how to create the Performance Collection Rules and particularly how to do the Performance Mapping for multiuple instances (all the running processes). Do you have any idea if this is doable at all? Thanks in advance for any hints, tips or tricks.

Hi Stoyan,

I think what you’re looking for is about 35 minutes in on the release webinar: Webinar: SCOM PowerShell Monitoring MP - YouTube

Hope this helps!

Hey (Evel Pinguin) :slight_smile:
I did watch the video, but it shows how sdata is being mapped for only one counter. I am not sure how I can dynamically map two counters (CPU and Memory) pro process and this for all running processes on the system. Do you have an idea how this can be done? Or an example?

Many thanks!

Hey Stoyan,

Ah, I think I can see where you’re getting stuck.

So when they say resist making the counter dynamic and that it’s not supported, this is true, and so I suppose you cannot do exactly what you are looking for. You can never make this fully dynamic. However, you can just statically define each counter in its own rule and then peel off the metrics you care about:

# Any Arguments specified will be sent to the script as a single string.
# If you need to send multiple values, delimit them with a space, semicolon or other separator and then use split.

$ScomAPI = New-Object -comObject "MOM.ScriptAPI"

# Collect your performance counter here.  Note that in order to support the DW this script MUST only return a single
# object/counter and those must be static values.  You can return multiple instances just fine though.

$Instances = @("Instance1", "Instance2")
$Metric = 42
$Metric2 = 420

Foreach ($Instance in $Instances)
$PropertyBag = $ScomAPI.CreatePropertyBag()
$PropertyBag.AddValue("Metric", $Metric)
$PropertyBag.AddValue("Metric2", $Metric2)

# Send output to SCOM

So two rules, leveraging cookdown means that the script only runs once. You can verify this if you like by using the LogScriptEvent method on the SCOMApi object:

$ScomAPI = New-Object -comObject "MOM.ScriptAPI"
$ScomAPI.LogScriptEvent("test",9999,2,"this is a test")

If you get more than one event, I suggest exporting the MP as XML and checking the scripts there. I’ve seen cases where something daft like an extra carriage return has snuck in and screwed up cookdown (just now when coming up with this example :man_facepalming:):

I hope this helps!


Hey EP,

many thnaks for the example, will definitely try this out!


1 Like