Share via


How to Query for Agents

Applies To: System Center 2012 - Operations Manager

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

An agent is an Operations Manager service that runs on each computer that you want to monitor. An agent captures information from the computer on which it is running, applies predefined rules to the captured data, and performs actions as defined by the rules. You can query for agents by defining criteria in the AgentManagedComputerCriteria 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

  • LastModified

  • DisplayName

The following code queries for all the agents that were modified after 10/25/2006:

/// <summary> 
/// Query for agents.
/// </summary>
using System;
using System.Collections.Generic;
using Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.Administration;
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
            // agents that were modified after 10/25/2006.
            AgentManagedComputerCriteria agentCriteria =
                new AgentManagedComputerCriteria(
                "LastModified >= '" +
                new DateTime(2006, 10, 25).ToString("G") + "'");

            IAdministrationManagement administration =  mg.Administration;

            Console.WriteLine("Querying for data...");
            IList<AgentManagedComputer> agents =
                administration.GetAgentManagedComputers(agentCriteria);

            // Display information about each agent.
            foreach (AgentManagedComputer agent in agents)
            {
                Console.WriteLine("Agent name: " + agent.Name);
                Console.WriteLine("IPAddress: " + agent.IPAddress);
                Console.WriteLine("Health State: " + agent.HealthState);
                Console.WriteLine("Version: " + agent.Version +
                    Environment.NewLine);
            }
        }
    }
}

See Also

Concepts

Operations Manager Data Queries Overview