You must know the name of the group you want to delete, and then you can delete the group from the Management Pack that contains the group. The following code example deletes a group named SampleGroup1. The DeleteMonitoringObjectGroup method is used to delete the group.

Visual Basic  Copy Code
Imports System
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports Microsoft.EnterpriseManagement
Imports Microsoft.EnterpriseManagement.Configuration
Imports Microsoft.EnterpriseManagement.Common
Imports Microsoft.EnterpriseManagement.Monitoring

Namespace SDKSamples
	Class Program
		Public Overloads Shared Function Main(ByVal args() As String) As Integer

			Dim mg As ManagementGroup
			mg = New ManagementGroup("localhost")

				DeleteGroup(mg, "SampleGroup1")
			Catch [error] As MonitoringException
			End Try
		End Function 'Main

		' ---------------------------------------------------------------------
		Private Shared Sub DeleteGroup(ByVal mg As ManagementGroup, _
			ByVal groupDisplayName As String)

			Dim groups As ReadOnlyCollection(Of MonitoringObjectGroup)
			Dim groupToDelete As MonitoringObjectGroup = Nothing

			groups = mg.GetRootMonitoringObjectGroups()

			For Each group As MonitoringObjectGroup In groups
				If group.DisplayName = groupDisplayName Then
					groupToDelete = group
					Exit For
				End If
			Next group

			If groupToDelete Is Nothing Then
				Throw New ApplicationException("Failed to retrieve the specified group")
				Dim monitoringClasses As ReadOnlyCollection(Of MonitoringClass)
				monitoringClasses = groupToDelete.GetMonitoringClasses()
			End If

		End Sub 'DeleteGroup

	End Class 'Program
End Namespace 'SDKSamples
C#  Copy Code
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement.Common;
using Microsoft.EnterpriseManagement.Monitoring;

namespace SDKSamples
	class Program
		static void Main(string[] args)
			ManagementGroup mg;

			mg = new ManagementGroup("localhost");

				DeleteGroup(mg, "SampleGroup1");
			catch (MonitoringException error)

		// ---------------------------------------------------------------------
		private static void DeleteGroup(
			ManagementGroup mg,
			string groupDisplayName
			ReadOnlyCollection<MonitoringObjectGroup> groups;
			MonitoringObjectGroup groupToDelete = null;

			groups = mg.GetRootMonitoringObjectGroups();

			foreach (MonitoringObjectGroup group in groups)
				if (group.DisplayName == groupDisplayName)
					groupToDelete = group;

			if (groupToDelete == null)
				throw new ApplicationException("Failed to retrieve the specified group");
				ReadOnlyCollection<MonitoringClass> monitoringClasses;
				monitoringClasses = groupToDelete.GetMonitoringClasses();

Send comments about this topic to Microsoft.