Skip to Main Content

PowerShell Community Management Pack in Action: adding a diagnostic to the monitor

Welcome to the third part of a series of posts that will run through using the PowerShell Community Management Pack for SCOM to enhance your SCOM monitoring.

In the first part of this series, I walked through using a PowerShell script to check the number of files in a remote share and then tweaked the code to allow for the use of a Run As Account and in the second part, we added a Performance Collection Rule.

Now we'll add a diagnostic to our original monitor. This diagnostic will list each file in the folder.

Let's go

One of the limitations of the SCOM console is that there is no option to directly create a diagnostic (or recovery) from the SCOM authoring tab. You need to locate the underlying monitor and add the diagnostic to the monitor.

The easiest way to do this is if you already have an open alert.

I can then click on the Alert Monitor hyperlink and go to the Diagnostic and Recovery Tab.

Click Add > Diagnostic for critical health state. And there is now an option for "Run a PowerShell script (Community)"

I've called my script ListFiles.ps1 and set it to run the diagnostic automatically when there is an alert (or, if you want to be correct, when there is a health state change to critical).

Make sure to set the diagnostic target to the correct class – that is the same class that the underlying monitor is targeted at).

Then the script (a quick and dirty list of the files).

Now, when the number of files in the share is over-threshold, there is:

Recap

We've created a diagnostic that will show a list of files in a remote share.

  1. This will automatically update when the monitor health state goes critical.
  2. It can also be run manually at any time.

Next step

The final post in the series will create a recovery task which can be used to delete the files in the folder.

Share this article to LinkedInShare this article on XShare this article to Facebook