September 2011 - Posts
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
For those of you that might be interested in automating some of your folder structures for your ConfigMgr 2012 Hydration or test labs the following should help guide you on how to create Console Folder 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 creating Consoler Folders:
Name, ObjectType, ObjectTypeName, parentContainerNodeID
The following is an example script creating A Application Console Folder Item Structure. Use the table above to create any console folder item you would like to have.
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: CreateConsoleFolderItem.vbs
'//
'// Purpose: Used to Create console Folder Items
'//
'// Usage: cscript CreateConsoleFolderItem.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.
'//
'//
'/////////////////////////////////////////////////////////////////////////////////////////////////////
Dim objFolder, NewContainerNodeID, aNewContainerNodeID, newfolder, newfolderpath
' 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
'// Create Application Console Folders
'// Create Application Console Root Folder
Call CreateConsoleFolder(swbemconnection, Location.SiteCode & " - Applications", 31, "SMS_Application",0)
'// Set Root Folder Variable for use later
set aNewContainerNodeID = NewContainerNodeID
'// Create Application Console Folders under Root Folder
Call CreateConsoleFolder(swbemconnection, "Adobe", 31, "SMS_Application", NewContainerNodeID)
Call CreateConsoleFolder(swbemconnection, "Microsoft", 31, "SMS_Application", aNewContainerNodeID)
Call CreateConsoleFolder(swbemconnection, "Oracle", 31, "SMS_Application", aNewContainerNodeID)
Call CreateConsoleFolder(swbemconnection, "Dell Inc.", 31, "SMS_Application", aNewContainerNodeID)
Call CreateConsoleFolder(swbemconnection, "Cisco", 31, "SMS_Application", aNewContainerNodeID)
Call CreateConsoleFolder(swbemconnection, "Citrix", 31, "SMS_Application", aNewContainerNodeID)
Call CreateConsoleFolder(swbemconnection, "7zip", 31, "SMS_Application", aNewContainerNodeID)
Sub CreateConsoleFolder(swbemconnection, name, objectType, objectTypeName, parentContainerNodeID)
Set newfolder = swbemconnection.Get("SMS_ObjectContainerNode").SpawnInstance_()
newfolder.Name = name
newfolder.ObjectType = objectType
newfolder.ObjectTypeName = objectTypeName
newfolder.ParentContainerNodeID = parentContainerNodeID
set newfolderpath = newfolder.Put_
set NewContainerNodeID = newfolderpath.Keys("ContainerNodeID")
End Sub
For those of you that might be interested in automating some of your collections for your ConfigMgr 2012 Hydration or test labs the following should help guide you on how to create static configmgr collections. There have been a few changes with collections in ConfigMgr 2012 which make the process of scripting collections slightly different.
First there are no more subcollections so we no longer have to supply the ParentCollection Property.
Secondly collections are split up into two different groups which cannot be mixed together, Device and user groups. There is a property to specify which type of collection you want to create called CollectionType that accepts the following parameters: “1 = User, 2 = Device”.
Lastly every collection has to be limited to another collection regardless of the type of collection being created. If you are creating a device collection then you need to limit that collection to another device collection and the same applies to user based collections they need to be limited to user based collections.
Below are the required parameters for creating a static collection:
Name, Comment, OwnedByThisSite, CollectionType, LimitToCollectionID
The following is an example script creating both a Device and User Collection.
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: CreateStaticCollections.vbs
'//
'// Purpose: Used to Create Static Collections
'//
'// Usage: cscript CreateStaticCollections.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
'// Create Static Device Collections
Call CreateStaticCollection(swbemconnection, "New Static Device collection", "New Static Device collection Comment", true, 2, "SMS00001")
'// Create Static User Collections
Call CreateStaticCollection(swbemconnection, "New Static User collection", "New Static User collection Comment", true, 1, "SMS00004")
Sub CreateStaticCollection(swbemconnection, newCollectionName, newCollectionComment, ownedByThisSite, CollectionType, ExistingLimitToCollectionID)
'// Create the collection.
Set newCollection = swbemconnection.Get("SMS_Collection").SpawnInstance_
newCollection.Name = newCollectionName
newCollection.Comment = newCollectionComment
newCollection.OwnedByThisSite = ownedByThisSite
newCollection.CollectionType = CollectionType
newCollection.LimitToCollectionID = ExistingLimitToCollectionID
'// Save the new collection and save the collection path for later.
Set collectionPath = newCollection.Put_
'// Get the collection.
Set newCollection = swbemconnection.Get(collectionPath.RelPath)
'// Call RequestRefresh to initiate the collection evaluator.
newCollection.RequestRefresh False
End Sub
For those of you that might be interested in automating some of your collections for your ConfigMgr 2012 Hydration or test labs the following should help guide you on how to create dynamic configmgr collections. There have been a few changes with collections in ConfigMgr 2012 which make the process of scripting collections slightly different.
First there are no more subcollections so we no longer have to supply the ParentCollection Property.
Secondly collections are split up into two different groups which cannot be mixed together, Device and user groups. There is a property to specify which type of collection you want to create called CollectionType that accepts the following parameters: “1 = User, 2 = Device”.
Lastly every collection has to be limited to another collection regardless of the type of collection being created. If you are creating a device collection then you need to limit that collection to another device collection and the same applies to user based collections they need to be limited to user based collections.
Below are the required parameters for creating a dynamic collection:
Name, Comment, OwnedByThisSite, CollectionType, LimitToCollectionID, queryForRule, ruleName
The following is an example script creating both a Device and User Collection.
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: CreateDynamicCollections.vbs
'//
'// Purpose: Used to Create Dynamic Collections
'//
'// Usage: cscript CreateDynamicCollections.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
'// Create Dynamic Device Collections
Call CreateDynamicCollection(swbemconnection, "New Dynamic Device Collection", "New Dynamic Device Collection Comment", true, "SELECT * from SMS_R_System", "New Rule Name", 2, "SMS00001")
'// Create Dynamic User Collections
Call CreateDynamicCollection(swbemconnection, "New Dynamic User Collection", "New Dynamic User Collection Comment", true, "SELECT * from SMS_R_User", "New Rule Name", 1, "SMS00004")
Sub CreateDynamicCollection(swbemconnection, newCollectionName, newCollectionComment, ownedByThisSite, queryForRule, ruleName, CollectionType, ExistingLimitToCollectionID)
'// Create the collection.
Set newCollection = swbemconnection.Get("SMS_Collection").SpawnInstance_
newCollection.Name = newCollectionName
newCollection.Comment = newCollectionComment
newCollection.OwnedByThisSite = ownedByThisSite
newCollection.CollectionType = CollectionType
newCollection.LimitToCollectionID = ExistingLimitToCollectionID
'// Save the new collection and save the collection path for later.
Set collectionPath = newCollection.Put_
'// Create a new collection rule object for validation
Set queryRule = swbemconnection.Get("SMS_CollectionRuleQuery")
'// Validate the query (good practice before adding it to the collection).
validQuery = queryRule.ValidateQuery(queryForRule)
'// continue with processing, if the query is valid.
If validQuery Then
'// Create the query rule.
Set newQueryRule = QueryRule.SpawnInstance_
newQueryRule.QueryExpression = queryForRule
newQueryRule.RuleName = ruleName
'// Add the new query rule to a variable.
Set newCollectionRule = newQueryRule
'// Get the collection.
Set newCollection = swbemconnection.Get(collectionPath.RelPath)
'// Add the rules to the collection.
newCollection.AddMembershipRule newCollectionRule
'// Call RequestRefresh to initiate the collection evaluator.
newCollection.RequestRefresh False
End If
End Sub