Skip to Main Content

PowerShell Community Management Pack in action - adding a recovery to the monitor

Welcome to the final 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.

In the third part we add a diagnostic to our original monitor to list out each file in the folder.

And now, in the final part, we'll add a recovery task to delete all the files in the folder.

Let's go

Let's find an open alert.

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

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

Give the script a name, set the recovery target to the same target class as the underlying monitor, and decide if you want the recovery task to run automatically - I have decided against this!

A quick and dirty script to delete all the files in a folder.

Then wait for a new alert:

Open Health Explorer and we can see that our diagnostic from part 3 has already run automatically and listed out the files in the folder. Right at the bottom, we have our recovery task available (but not executed).

Let's run the recovery task (and make sure that the SCOM agent action account has permission to delete files in the folder otherwise, you'll see the same error as I got in the screenshot below!).

But once I set read/write permissions for the SCOM agent action account, the recovery executed fine (see the very bottom item in the screenshot above) and that the monitor has returned to a healthy state.

Next Steps

That completes this series of articles.

Part 1 – A Monitor and Run As Profile / Run As Account - PowerShell Community Management Pack in Action - Monitors and Run As Accounts - SquaredUp DS

Part 2 – Performance Collection Rule - PowerShell Community Management Pack in Action - Performance Collection Rule - SquaredUp DS

Part 3 – Diagnostic - PowerShell Community Management Pack in Action - Adding a diagnostic to the monitor - SquaredUp DS

Part 4 – Recovery - PowerShell Community Management Pack in Action - Adding a recovery to the monitor - SquaredUp DS

I hope the series was useful. Let me know what you would like to see in future articles.

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

Technical Product Manager – SCOM products