How to Move 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
You move one or more Microsoft System Center Configuration Manager 2007 console folder items from one location to another by using the SMS_ObjectContainerNodeMoveMembers Method in Class SMS_ObjectContainerItem method. To move a set of items, call MoveMembers passing an array of item instance keys—the source folder identifier, the destination folder identifier, and the type of the item.
Note
An item can be moved only within its own folder type (SMS_ObjectContainerItem.ObjectType). For example, attempting to move a query item to a package folder fails.
The instance key for an item is guaranteed to be unique only for the same type of item. For example, a package item can have the same instance key as an advertisement item. The type of the item (SMS_ObjectContainerItem.ObjectType) should be inspected to ensure that the correct item is moved.
Configuration Manager 2007 objects in the root folder of a given type do not have an associated SMS_ObjectContainerItem instance. To overcome this, pass 0 to the ContainerNodeID parameter of MoveMembers.
To move a console folder item
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
Create an array of container identifiers for the folders you want to move.
Call the SMS_OBjectContainerItem class MoveMembers method to move the folders to the destination folder.
Example
The following example moves a console folder item that is identified by the item object identifier (ItemObjectID) and object type (objectType). SourceContainerID is the source folder and destinationContainerID is the destination folder
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Sub MoveConsoleFolderItem(connection, _
itemObjectID, _
objectType, _
sourceContainerID, _
destinationContainerID)
Dim inParameters
Dim outParamemters
Dim itemClass
Dim sourceItems
On Error Resume Next
' Moving only one folder.
sourceItems = Array(itemObjectID)
' Obtain the class definition object of a SMS_ObjectContainerNode object.
Set itemClass = connection.Get("SMS_ObjectContainerItem")
If Err.Number<>0 Then
Wscript.Echo "Couldn't get container node item class"
Exit Sub
End If
' Set up the in parameters.
Set inParameters = itemClass.Methods_("MoveMembers").InParameters.SpawnInstance_
WScript.Echo sourceItems(0)
inParameters.InstanceKeys = sourceItems
inparameters.ContainerNodeID = sourceContainerID
inParameters.TargetContainerNodeID = destinationContainerID
inParameters.ObjectType = objectType
' Call the method.
Set outParameters = _
connection.ExecMethod( "SMS_ObjectContainerItem", "MoveMembers", inParameters)
If Err.Number<>0 Then
Wscript.Echo "Couldn't call method"
Exit Sub
End If
End Sub
public void MoveConsoleFolderItem(WqlConnectionManager connection, string itemObjectID, Int32 objectType, Int32 sourceContainerID, Int32 destinationContainerID)
{
try
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
string[] sourceItems = new string[1];
// Only one item is being moved, the array size is 1.
sourceItems[0] = itemObjectID;
parameters.Add("InstanceKeys", sourceItems);
parameters.Add("ContainerNodeID", sourceContainerID);
parameters.Add("TargetContainerNodeID", destinationContainerID);
parameters.Add("ObjectType", objectType);
connection.ExecuteMethod("SMS_ObjectContainerItem", "MoveMembers", parameters);
}
catch (SmsException e)
{
Console.WriteLine("Failed to move folder item. Error: " + e.Message);
throw;
}
}
The example method has the following parameters:
Parameter | Type | Description |
---|---|---|
connection |
|
A valid connection to the SMS Provider. |
itemObjectID |
|
The item's key. For more information, see the SMS_ObjectContainerItem class InstanceKey property. |
objectType |
|
The item type. For more information, see the SMS_ObjectContainerItem class ObjectType property. |
sourceContainerID |
|
The identifier for the source console folder. For more information, see the SMS_ObjectContainerNode class ContainerNodeID property. |
destinationContainerID |
|
The identifier for the destination console folder. For more information, see the SMS_ObjectContainerNode class ContainerNodeID property. |
Compiling the Code
Namespaces
System
System.Collections.Generic
System.ComponentModel
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine (Only required if the connection manager is of type WqlConnectionManager.)
Assembly
microsoft.configurationmanagement.managementprovider
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 Folder Item
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