How to Approve Manual Agent Installations

Updated: January 31, 2012

Applies To: System Center 2012 - Operations Manager

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 Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.Administration;
using Microsoft.EnterpriseManagement.Common;

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

			ManagementGroup mg = new ManagementGroup("localhost");
		 
			IList<AgentPendingAction> pendingActions = mg.Administration.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
			{
				mg.Administration.ApproveAgentPendingActions(approvedActions);
		}
			catch (UnknownServiceException)
			{
				Console.WriteLine("No agents were approved (possibly because no agents were waiting for approval).");
		}
	}
}
}

See Also