Partilhar via


How to Create a Configuration Manager Console Folder Item

Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2

In Microsoft System Center Configuration Manager 2007, because there are no SMS_ObjectContainerItem Server WMI Class instances for Configuration Manager 2007 objects in the root folder of a given Configuration Manager object type, a new SMS_ObjectContainerItem instance must be created for each Configuration Manager object that is moved from the root folder to a subfolder. For example, when reports in the root folder are organized into more meaningful folders, a new SMS_ObjectContainerItem instance must be created for each report that is placed in a subfolder.

The following properties must be supplied when you create an instance of SMS_ObjectContainerItem:

  • ContainerNodeID - The identifier for the console folder that contains the item. This value maps to the SMS_ObjectContainerNode class ContainerNodeId property. For more information about creating console folders, see How to Create a Configuration Manager Console Folder.

  • InstanceKey - The item's key. For example the SMS_Package class PackageID property value.

  • ObjectType -The type of the item, for example, 2 for a package. For more information, see the SMS_ObjectContainerItem class ObjectType property.

To create a console folder item

  1. Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.

  2. Create an SMS_ObjectContainerItem object.

  3. Populate the object properties.

  4. Commit the changes.

Example

The following example creates a new console folder item for a Configuration Manager object that is identified by its instance identifier (instanceID) and its object type (objectType). The new folder item is created in the folder identified by nodeID.

For information about calling the sample code, see Calling Configuration Manager Code Snippets.

Sub CreateConsoleFolderItem(connection, instanceID, objectType, nodeID)

    Dim folderItem
    Set folderItem = connection.Get("SMS_ObjectContainerItem").SpawnInstance_()

    folderItem.InstanceKey = instanceID
    folderItem.ObjectType = objectType
    folderItem.ContainerNodeID = nodeID

    folderItem.Put_

End Sub   
public void CreateConsoleFolderItem(WqlConnectionManager connection, string instanceID, Int32 objectType, Int32 nodeID)
{
    try
    {
        IResultObject folderItem = connection.CreateInstance("SMS_ObjectContainerItem");

        folderItem["InstanceKey"].StringValue = instanceID;
        folderItem["ObjectType"].IntegerValue = objectType;
        folderItem["ContainerNodeID"].IntegerValue = nodeID;

        folderItem.Put();
    }
    catch (SmsException e)
    {
        Console.WriteLine("Failed to create folder item. Error: " + e.Message);
        throw;
    }
}

The example method has the following parameters:

Parameter Type Description

connection

  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider.

InstanceID

  • Managed: String

  • VBScript: String

The item's key. For more information, see the SMS_ObjectContainerItem class InstanceKey property.

objectType

  • Managed: Int32

  • VBScript: Integer

The item type. For more information, see the SMS_ObjectContainerItem class ObjectType property.

nodeID

  • Managed: Int32

  • VBScript: Integer

The type of the item. For more information, see the SMS_ObjectContainerItem class ContainerNodeID property and the SMS_ObjectContainerNode class ContainerNodeId property.

Compiling the Code

This C# example requires:

Namespaces

System

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

Robust Programming

For more information about error handling, see About Configuration Manager Errors.

Security

For more information about securing Configuration Manager applications, see About Securing Configuration Manager Applications.

See Also

Concepts

About Configuration Manager Console Folders
Configuration Manager Objects
How to Create a Configuration Manager Console Folder
How to Create a Configuration Manager Console Search Folder
How to Delete a Configuration Manager Console Folder
How to Move a Configuration Manager Console Folder
How to Move a Configuration Manager Console Folder Item