This article is a sequence of real world examples on using PowerShell in SharePoint 2016. In this article, we will discuss how we will use PowerShell cmdlets in managing the Health Analysis rule in SharePoint. We will try to cover all the available cmdlets i.e. get, enable and, disable.

Scenario

KrossFarm administrator has some known issues with their environments but certain Health Analysis Rule is annoying them. So they want to disable all rules in the Lower environment (dev farms) and disable certain rules in the Production Farm. Also, they found one of the Health Rules (TimerRecycleFailed) is already disabled in the Production farm in which they want to enable it.

Tasks

  • Get the Health Analysis Rule
  • Disable All Rules in Dev and a few in Production
  • Enable the Timer Job rule in Production

Split the scenario into two examples. In the first example, let's work in Dev farm and disable all Health Rules while in the second example let's disable a couple of rules and enable one rule in Production.

Example 1

Let's start with dev farm.

Get

First, we will list all Health Rules in the farm. For that, we will run this command:

Get-SPHealthAnalysisRule
You will get the output like this. It includes Name, ID, Enabled Status, Category and Summary of all rules. You can write them into a txt file for better understanding.

Disable:

Now we want to disable all Health Analysis rules.

Get-SPHealthAnalysisRule | Disable-SPHealthAnalysisRule
This command will get the Health Rule and disable one by one. It asks you for the confirmation and if you press “Y” then it will repeat this for rules but if you type “A” that’s mean you said, “Yes to All ” (as above). Output like this. Now if we want to check the status of the rule then we have to re-run the get command like this.

Get-SPHealthAnalysisRule | select name enabled

You will see Enabled column is False for all rules.

Example 2

In production, Krossfarm Administrator wants to disable the all the timer ContentDbsAreTooLarge, ReadOnlyDatabase and WindowsClassicTest and they want to enable the TimerRecycleFailed rule.

Get

Let's disable all three Health Rules one by one.

$HR = Get-SPHealthAnalysisRule ContentDbsAreTooLarge
Disable-SPHealthAnalysisRule $hr
Get-SPHealthAnalysisRule $HR

The output will be like this:

Now repeat the above PowerShell commands for other two rules:

$HR = Get-SPHealthAnalysisRule ReadOnlyDatabase
Disable-SPHealthAnalysisRule $hr
Get-SPHealthAnalysisRule $HR

And the same thing for WindowsClassicTest

$HR = Get-SPHealthAnalysisRule WindowsClassicTest
Disable-SPHealthAnalysisRule $hr
Get-SPHealthAnalysisRule $HR

Enable:

Now we want to enable the Timer Job Health Rule.

$HR = Get-SPHealthAnalysisRule TimerRecycleFailed
Disable-SPHealthAnalysisRule $hr
Get-SPHealthAnalysisRule $HR

Output will be like this:

Note

This as an example. The situation varies in your environment. This example is just for learning the purpose and gives you an idea how to use above PowerShell commands.

Reference

See Also