Manage Health Analyzer Rules in SharePoint 2013 using PowerShell

We all know and hate the Health Analyzer that comes with SharePoint 2013 out-of-the-box.​ The Health Analyzer is a nice concept that Microsoft introduced back in SharePoint 2010, but it quickly becomes more annoying than anything. It is there to help you keep in line with the best practices that have been established by Microsoft, but for dev environments it is probably not something you wish to use. I know that personally, all of the development machines I have built all have that good all red notification bar at the top of Central Administration.

20150106-01.png

Most of the time, at least for me, the same errors always come back: “Databases exist on servers running SharePoint Foundation”, “The current server is running low on memory”, etc. Even if the fact that these errors show up in Central Administration all the time is not critical and does not affect performance, it still is freaking annoying to me. So I decided to go and use PowerShell to disable some of the Health Analyzer Rules in my dev environments so that they don’t show up anymore.

The first thing for you to know is that in order for you to acquire a list of all Health Analyzer Rules that exist on the server, you need to call the Get-SPHealthAnalysisRule PowerShell cmdlet. This returns a complete list of all rules on the server. On my current dev environment, running the December 2014 CU, I have a total of 72 rules defined. In my case I am specifically looking to disable the “Database exist on servers running SharePoint Foundation” rule, because all of my dev machines are mainly a Single Farm instance having the SQL Server running directly on the SharePoint Server. In order for me to find the rule I am looking for, I can use a wildcard Where query on the list of all rules, querying on the summary property which represents the description of the error:

Get-SPHealthAnalysisRule | Where{$_.Summary -like ‘*Databases exist on servers running SharePoint Foundation*’}

20150106-02.png

In order for us to disable it, we need to assign this result to a variable, and then set its Enabled property to false. Note that you could also use the Disable-SPHealthAnalysisRule cmdlet.

$rule = Get-SPHealthAnalysisRule | Where{$_.Summary -like ‘*Databases exist on servers running SharePoint Foundation*’}

$rule.Enabled = $false

$rule.Update()

20150106-03.png

Now, you need to understand that simply disabling a Health Analysis Rule is not automatically going to remove its associated errors from the list in Central Administration. As we can see in the next screenshot, I still have my error displayed in the list. First off, you’ll need to go and delete the error entry from the Error List in Central Administration, for this example, I’ve done it manually.

20150106-04.png

What we need to do now is to run the timer job responsible for checking the Health Analyzer Rules. Problem is, there are about 25 timer jobs related to the Health Analyzer to choose from.

20150106-05.png

Now, you can try to go and guess which one to run by yourself, but I prefer to do it using a method of mine called “Brute Force”.  I simply get a reference to all timer jobs responsible for the Health Analyzer, loop through each of them and run them on the spot. The following line of PowerShell will allow you to achieve this. It gets all timer jobs that have the word “Health” in their names, and assigned them to a variable, then we loop through each entry in that variable, and call the RunNow() method on each.

$healthJobs = Get-SPTimerJob | Where {$_.Name -like ‘*Health*’}

foreach($healthJob in $healthJobs){$healthJob.RunNow()}

Once this has been executed, we should be able to see that the error is no longer in our list in Central Administration.

20150106-06.png

Microsoft Premier Field Engineer – SharePoint

Leave a Comment

Your email address will not be published. Required fields are marked *

*
*