Partager via


How to Delete Instances

Applies To: System Center 2012 - Service Manager

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

Service Manager provides the IncrementalDiscoveryData class which you can use to perform add or delete operations on a set of EnterpriseManagementObjects. This class has a method named Remove which when it is called, adds the supplied object to a list of items to remove from Service Manager. Once all the items have been added to the Remove part of the IncrementalDiscoveryData object, the Commit method is called which will delete the EnterpriseManagementObjects from Service Manager.

One of the overloads for the Remove method takes the EnterpriseManagementObject that you want to delete, and a ManagementPackClass that represents the type you want to delete it from. Service Manager keeps objects that represent each class your EnterpriseManagementObject uses. For example, if you have Class B inherit from Class A, and then create an instance of Class B, there will be two objects (both accessed through the single EnterpriseManagementObject instance) created and tracked in the database, one for each class. When a management pack class is passed to Remove, the data object of that class, for the EnterpriseManagementObject instance, is removed.

To delete EnterpriseManagementObjects

  1. Connect to the server by using the EnterpriseManagementGroup class.

  2. Create an instance of the IncrementalDiscoveryData class.

  3. Obtain reference to the EnterpriseManagementObject you want to delete.

  4. Call the Remove method, providing an EnterpriseManagementObject instance.

  5. Call the Commit method, providing the EnterpriseManagementGroup connection object.

Example

The following example connects to a server, obtains an EnterpriseManagementObject by GUID, and removes it from the server:

EnterpriseManagementGroup mg = new EnterpriseManagementGroup("localhost");
IncrementalDiscoveryData discovery = new IncrementalDiscoveryData();

EnterpriseManagementObject existingObject = mg.EntityObjects.GetObject<EnterpriseManagementObject>(new Guid("ec14c9b3-22c5-8bbb-9e4e-a74a124dc3e5"), ObjectQueryOptions.Default);

discovery.Remove(existingObject);

discovery.Commit(mg);

Compiling the Code

Namespaces

System

Microsoft.EnterpriseManagement

Microsoft.EnterpriseManagement.Common

Microsoft.EnterpriseManagement.ConnectorFramework

Assemblies

mscorlib

Microsoft.EnterpriseManagement.Core

See Also

Tasks

How to Create an Instance
How to Get a Single Instance
How to Get All Instances
How to Query for Instances

Reference

IncrementalDiscoveryData
EnterpriseManagementObject

Other Resources

Scenario: Working with Instances