다음을 통해 공유


How to Query for Tasks

Applies To: Operations Manager 2007 R2, Operations Manager 2007 SP1, System Center Operations Manager 2007

In Operations Manager 2007, you can run predefined tasks that are included in your imported Management Packs, or you can create your own tasks. You can have a batch file or script run as a task remotely or locally. You can query for tasks by defining criteria in the MonitoringTaskCriteria class constructor. The criteria syntax is defined in Criteria Expression Syntax. The following property names are valid names that can be used in the criteria expression:

  • Id

  • Name

  • ManagementPackId

  • TargetMonitoringClassId

  • Enabled

  • Category

  • DisplayName

  • Description

  • Accessibility

  • Remotable

  • Timeout

  • TimeAdded

  • LastModified

The following code queries for the maintenance tasks that have SystemCenter in their name.

/// <summary> 
/// Query for tasks.
/// </summary>
using System;
using System.Collections.ObjectModel;
using Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement.Monitoring;

namespace SDKSamples
{
    class Program
    {
        static void Main(string[] args)
        {
            ManagementGroup mg = new ManagementGroup("localhost");

            // The criteria specifies that you want to collect
            // all the maintenance tasks that have SystemCenter in their name.
            MonitoringTaskCriteria taskCriteria =
                new MonitoringTaskCriteria(
                "Category = 'Maintenance' AND Name LIKE '%SystemCenter%'");

            Console.WriteLine("Querying for data...");
            ReadOnlyCollection<MonitoringTask> tasks =
                mg.GetMonitoringTasks(taskCriteria);

            // Display information about each task.
            foreach (MonitoringTask task in tasks)
            {
                Console.WriteLine("Task name: " + task.Name);
                Console.WriteLine("Status: " + task.Status.ToString());
                Console.WriteLine("Category: " + task.Category);
                Console.WriteLine("Description: " + task.Description +
                    Environment.NewLine);
            }
        }
    }
}