How to Approve Manual Agent Installations

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

If you do not need to fully automate the deployment of agents but you still want to automate the approval of manually deployed agents, you can query the pending actions that require approval, and then approve them by using the Operations Manager class libraries.

Example

The following example demonstrates how to approve a pending action that adds a computer with a manually installed agent to the Management Group. Other types of pending actions can be approved in a similar manner.

/// <summary>
/// Allows all computers with a manually installed agent 
/// to join the Management Group.
/// </summary>
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.Administration;
using Microsoft.EnterpriseManagement.Common;
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement.Monitoring;
using System.Text;

namespace SDKSamples
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Approving manual agent installations.");

            ManagementGroup mg = new ManagementGroup("localhost");
            ManagementGroupAdministration mga = mg.GetAdministration();

            ReadOnlyCollection<AgentPendingAction> pendingActions = mga.GetAgentPendingActions();
            if (pendingActions.Count == 0)
            {
                Console.WriteLine("There are no pending actions for this Management Group.");
                return;
            }

            List<AgentPendingAction> approvedActions = new List<AgentPendingAction>();
            foreach (AgentPendingAction action in pendingActions)
            {
                // Approve pending actions only for manually installed agents.
                if (action.AgentPendingActionType == AgentPendingActionType.ManualApproval)
                {
                    Console.WriteLine("Agent " + action.AgentName + " waiting for approval...");
                    
                    approvedActions.Add(action);
                    Console.WriteLine(action.AgentName + " has been approved.");
                    
                }
            }

            try
            {
                mga.ApproveAgentPendingActions(approvedActions);
            }
            catch (UnknownServiceException e)
            {
                Console.WriteLine("No agents were approved (possibly because no agents were waiting for approval).");
            }
        }
    }
}
' Allows all computers with a manually installed agent 
' to join the Management Group.
Imports System
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports Microsoft.EnterpriseManagement
Imports Microsoft.EnterpriseManagement.Administration
Imports Microsoft.EnterpriseManagement.Common
Imports Microsoft.EnterpriseManagement.Configuration
Imports Microsoft.EnterpriseManagement.Monitoring
Imports System.Text

Namespace SDKSamples
    Class Program
        Public Overloads Shared Function Main(ByVal args() As String) As Integer
            Console.WriteLine("Approving manual agent installations.")

            Dim mg As ManagementGroup = New ManagementGroup("localhost")
            Dim mga As ManagementGroupAdministration = mg.GetAdministration()

            Dim pendingActions As ReadOnlyCollection(Of AgentPendingAction) = mga.GetAgentPendingActions()
            If pendingActions.Count = 0 Then
                Console.WriteLine("There are no pending actions for this Management Group.")
                Return 1
            End If

            Dim approvedActions As List(Of AgentPendingAction) = New List(Of AgentPendingAction)()
            Dim action As AgentPendingAction
            For Each action In pendingActions
                ' Approve pending actions only for manually installed agents.
                If action.AgentPendingActionType = AgentPendingActionType.ManualApproval Then
                    Console.WriteLine("Agent " & action.AgentName & " waiting for approval...")

                    approvedActions.Add(action)
                    Console.WriteLine(action.AgentName & " has been approved.")

                End If
            Next

            Try
                mga.ApproveAgentPendingActions(approvedActions)
            Catch e As UnknownServiceException
                Console.WriteLine("No agents were approved (possibly because no agents were waiting for approval).")
            End Try
        End Function
    End Class
End Namespace

See Also

Tasks

How to Install, Remove, or Repair an Agent

Other Resources

Automating Operations Manager Administration