I wanted to disable the SharePoint Health Rules in my Powershell script but it seemed the corresponding Health Report Item was not effected by the disable cmdlet.
While working out how Microsoft has implemented this functionality, I thought let’s share some details and the function that sets the Health Rules and the Severity of the Reports List item.
Some ways of getting the possible values of the Health Rules:
1 2 3 4 5 6 |
#Customize the enum with a -Join and " - " [Microsoft.SharePoint.Administration.Health.SPHealthCheckErrorLevel].GetEnumValues() | %{Write-Host "$([int]$_) - $_"} [Microsoft.SharePoint.Administration.Health.SPHealthCheckErrorLevel].GetEnumValues() | %{@([int]$_,$_) -Join " - "} #Get the choices from the list field with guid "505423c5-f085-48b9-9432-12073d643ba5" ([Microsoft.SharePoint.Administration.Health.SPHealthReportsList]::Local.Fields | ?{$_.internalname -eq "HealthReportSeverity"}).Choices [Microsoft.SharePoint.Administration.Health.SPHealthReportsList]::Local.Fields.GetFieldByInternalName("HealthReportSeverity").Choices |
The choices that are available:
- 0 – RuleExecutionFailure
- 1 – Error
- 2 – Warning
- 3 – Information
- 4 – Success
The Health Rules (Get-SPHealthAnalysisRule) and the Health Reports List (SPHealthReportsList) Items can be linked by the Rule Summary and the Report Item Name, another option is the value for the Field “HealthRuleType”. In the last case you need to get the rule from the internal SharePoint Rules List (SPHealthRulesList):
1 |
[Microsoft.SharePoint.Administration.Health.SPHealthRulesList]::Local.Items | ?{$_.Name -eq "Long Name"} |
My function that takes an XML as input and disables the SharePoint Health Analysis Rules and sets the value in the Health Analysis Report List:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
function DisableHealthRules{ param ( [Parameter(Mandatory=$true)] [xml]$xmlinput ) $HealthReportListItems = [Microsoft.SharePoint.Administration.Health.SPHealthReportsList]::Local.Items foreach($rule in $xmlinput.Configuration.Farm.DisableHealthRules){ Write-Host "Disabling Health Analysis Rule $($rule.name) " -NoNewLine $HealthRule = Get-SPHealthAnalysisRule | ?{$_.Name -eq $rule.name} If($HealthRule){ If($HealthRule.Enabled -eq $True){ $HealthRule | Disable-SPHealthAnalysisRule -Confirm:$false Write-Host "Success" -Fore Green }Else{ Write-Host "Already disabled" -Fore Green } Write-Host "Setting current Health Report Severity value for Rule $($rule.name) " -NoNewLine $HealthReportItem = $HealthReportListItems | ?{$_.Name -eq $HealthRule.Summary} $HealthReportItem["HealthReportSeverity"] = "4 - Success" $HealthReportItem.Update() Write-Host "Success" -Fore Green }Else{ Write-Host "Failed: No Health Rule found by name" -Fore Red } } } |
The corresponding XML part:
1 2 3 4 5 6 7 8 9 10 |
<?xml version="1.0" ?> <Configuration> <Farm> <DisableHealthRules name="AppServerDrivesAreNearlyFullWarning"/> <DisableHealthRules name="AppServerDrivesAreNearlyFull"/> <DisableHealthRules name="SqlServerDrivesAreNearlyFull"/> <DisableHealthRules name="PagingFileSizeShouldExceedRam"/> <DisableHealthRules name="UserProfileLeadersExplicitlyAssignedHealthRule"/> </Farm> </Configuration> |