How to Get All 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.]
The EnterpriseManagementGroup object that is used to connect to the server, has a property named EntityObjects. EntityObjects let you to read multiple objects from Service Manager by using the GetObjectReader method. GetObjectReader provides overloads that can get enterprise management objects by using a list of identifiers, the management pack class type of the objects, or by querying through criteria.
To obtain all instance of a management pack class
Connect to the server by using the EnterpriseManagementGroup class.
Obtain reference to the ManagementPackClass definition that you want to obtain all instances of.
Call the method GetObjectReader implemented by the EntityObjects property. Provide the ManagementPackClass from the previous step.
The result of the previous step will be a IObjectReader object. This object contains the ManagementPackClass object instances and can be enumerated.
Example
The following example obtains a management pack class from a management pack, and retrieves all instances of that class from Service Manager. The identifiers of the instances are added to a List object:
EnterpriseManagementGroup mg = new EnterpriseManagementGroup("localhost");
ManagementPack mp = mg.GetManagementPack("RePackaging.Library", null, new Version());
ManagementPackClass requestClass = mp.GetClass("RePackaging.Request");
IObjectReader<EnterpriseManagementObject> reader;
List<Guid> objectIds;
reader = mg.EntityObjects.GetObjectReader<EnterpriseManagementObject>(requestClass, ObjectQueryOptions.Default);
objectIds = new List<Guid>(reader.MaxCount);
foreach (var item in reader)
{
objectIds.Add(item.Id);
}
Compiling the Code
Namespaces
System |
System.Collections.Generic |
Microsoft.EnterpriseManagement |
Microsoft.EnterpriseManagement.Common |
Microsoft.EnterpriseManagement.Configuration |
Assemblies
mscorlib |
Microsoft.EnterpriseManagement.Core |
See Also
Tasks
How to Create an Instance
How to Get a Single Instance
How to Query for Instances
How to Delete Instances
Reference
EnterpriseManagementGroup
EntityObjects
GetObjectReader
IObjectReader
ManagementPackClass