ConfigMgr 2012–Move Console Items
For those of you that might be interested in Moving objects around in your ConfigMgr 2012 Hydration or test labs the following should help guide you on how to Move Console Items in ConfigMgr 2012. There is a decent amount of available options and I will try and provide them in the below table:
| ObjectType | ObjectTypeName |
| 5000 | SMS_Collection_Device |
| 5001 | SMS_Collection_User |
| 31 | SMS_Application |
| 2 | SMS_Package |
| 17 | SMS_StateMigration |
| 9 | SMS_MeteredProductRule |
| 11 | SMS_ConfigurationItem |
| 2011 | SMS_ConfigurationBaselineInfo |
| 7 | SMS_Query |
| 1011 | SMS_SoftwareUpdate |
| 25 | SMS_Driver |
| 23 | SMS_DriverPackage |
| 18 | SMS_ImagePackage |
| 14 | SMS_OperatingSystemInstallPackage |
| 19 | SMS_BootImagePackage |
| 20 | SMS_TaskSequencePackage |
Below are the required parameters for Moving Console Items:
InstanceKeys, ContainerNodeID, TargetContainerNodeID, ObjectType
The itemObjectID in this scenario is the collection ID of the collection I want moved. You can find this information in the console by Right clicking and going to properties of the collection to retrieve the collection id or by querying the class in WMI.
The TargetContainerNodeID can be retrieved from the appropriate instance of the SMS_ObjectContainerNode class in WMI. Simply look for the ContainerNodeID of the folder that you want your object moved to for this parameter.
The following is an example script moving a collection to a Device Collection Folder created previously. Use the table above to move any console item.
Or you can download the script from the following Link.
Disclaimer: This code was created and tested on ConfigMgr 2012 (Beta) 2 and is subject to change.
'/////////////////////////////////////////////////////////////////////////////////////////////////////
'//
'// Script: MoveConsoleFolderItem.vbs
'//
'// Purpose: Used to Move Console Folder Items
'//
'// Usage: cscript MoveConsoleFolderItem.vbs
'//
'// Version: 1.0 - 04 Sept 2011 - Brandon Linton
'//
'// Disclaimer: This script is provided "AS IS" with no warranties, confers no rights and
'// is not supported by the authors or Inkbal Consulting, LLC.
'//
'//
'/////////////////////////////////////////////////////////////////////////////////////////////////////
' Setup a connection to the local provider.
Set swbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set swbemconnection= swbemLocator.ConnectServer(".", "root\sms")
Set providerLoc = swbemconnection.InstancesOf("SMS_ProviderLocation")
For Each Location In providerLoc
If location.ProviderForLocalSite = True Then
Set swbemconnection = swbemLocator.ConnectServer(Location.Machine, "root\sms\site_" + Location.SiteCode)
Exit For
End If
Next
'// Move Console Folder item
Call MoveConsoleFolderItem(swbemconnection, "C0100108", 5000, 0, 16777220)
Sub MoveConsoleFolderItem(Connection, itemObjectID, ObjectType, SourceContainerNodeID, DestinationTargetContainerNodeID)
Dim objInParam, objOutParams, objInstance, sourceItems
On Error Resume Next
' Moving only one folder.
sourceItems = Array(itemObjectID)
' Obtain the class definition object of a SMS_ObjectContainerNode object.
Set objInstance = swbemconnection.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 objInParam = objInstance.Methods_("MoveMembers").inParameters.SpawnInstance_()
'wscript.echo sourceItems(0)
objInParam.Properties_.Item("InstanceKeys") = sourceItems
objInParam.Properties_.Item("ContainerNodeID") = SourceContainerNodeID
objInParam.Properties_.Item("TargetContainerNodeID") = DestinationTargetContainerNodeID
objInParam.Properties_.Item("ObjectType") = ObjectType
' Call the method.
Set objOutParams = swbemconnection.ExecMethod("SMS_ObjectContainerItem","MoveMembers",objInParam)
' Return Results
If objOutParams.ReturnValue<>0 Then
Wscript.echo "Collection Failed to Move"
Else
Wscript.echo "Collection Moved Successfully!"
End if
End Sub