SPHealthRulesList Class

Represents a list of SharePoint Health Analyzer rule definitions registered with the farm.

System.Object
  Microsoft.SharePoint.SPSecurableObject
    Microsoft.SharePoint.SPList
      Microsoft.SharePoint.Administration.Health.SPHealthRulesList

Namespace:  Microsoft.SharePoint.Administration.Health
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

'Declaration
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class SPHealthRulesList _
	Inherits SPList _
	Implements IDisposable
'Usage
Dim instance As SPHealthRulesList

This class represents the Health Rules list in the Monitoring section of Central Administration. A farm administrator can use the Health Rules list to edit the settings for a health rule, changing where or when the rule runs, or even disabling the rule altogether.

To get an instance of the SPHealthRulesList class, access the static Local property. Once you have SPHealthRulesList object, you can query the list as you would any SPList object.

Important noteImportant

The SPHealthRulesList object returned by the Local property uses unmanaged resources. You are responsible for releasing those resources. One way to do that is to call the Dispose() method when you no longer need the object.

The following example is a console application that prints the title and schedule for every rule in the Health Rules list for the farm. Note that in order to access the Health Rules list, the local server must be joined to the farm.

Imports System
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Administration
Imports Microsoft.SharePoint.Administration.Health

Module Test

    Sub Main()

        If SPFarm.Joined Then

            Using list As SPHealthRulesList = SPHealthRulesList.Local

                ' Get a collection of rule definitions in alphabetical order.
                Dim query As SPQuery = New SPQuery()
                query.Query = "<OrderBy><FieldRef Name='LinkTitleNoMenu' /></OrderBy>"
                Dim rules As SPListItemCollection = list.GetItems(query)

                ' Print the title, date, and status for each item.
                Dim rule As SPListItem
                For Each rule In rules
                    Console.WriteLine(vbCrLf + "{0} Runs: {1}", _
                            rule(SPBuiltInFieldId.LinkTitleNoMenu).ToString(), _
                            rule(SPBuiltInFieldId.HealthRuleSchedule).ToString())
                Next

            End Using
        End If
        Console.Write(vbCrLf + "Press ENTER to continue...")
        Console.Read()
    End Sub

End Module

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show: