How to Modify a Collection
Updated: November 1, 2013
Applies To: System Center 2012 Configuration Manager, System Center 2012 Configuration Manager SP1, System Center 2012 R2 Configuration Manager
To Modify a Collection
Set up a connection to the SMS Provider.
Get the specific collection instance by using the collection ID provided.
Display the current property values (name and comment properties used as examples).
Modify the example property values using the name and comment values passed in.
Example
The following example method shows how to modify collection properties.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Sub RenameCollection(connection, collectionID, name, comment) Dim collection Set collection = connection.Get("SMS_Collection.CollectionID='" & collectionID & "'") WScript.Echo "-- Collection " & collectionID & " --" WScript.Echo "Name before: " & collection.Name WScript.Echo "Comment before: " & collection.Comment collection.Name = name collection.Comment = comment collection.Put_ WScript.Echo "" WScript.Echo "Name after: " & collection.Name WScript.Echo "Comment after: " & collection.CommentEnd Sub
public void RenameCollection(WqlConnectionManager connection, string collectionID, string name, string comment){ IResultObject collection = connection.GetInstance(string.Format("SMS_Collection.CollectionID='{0}'", collectionID)); Console.WriteLine("-- Collection {0} --", collectionID); Console.WriteLine("Name before: {0}", collection["Name"].StringValue); Console.WriteLine("Comment before: {0}", collection["Comment"].StringValue); collection["Name"].StringValue = name; collection["Comment"].StringValue = comment; collection.Put(); collection.Get(); Console.WriteLine(); Console.WriteLine("Name after: {0}", collection["Name"].StringValue); Console.WriteLine("Comment after: {0}", collection["Comment"].StringValue);}
Compiling the Code
The C# example requires:
System
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
mscorlib
Robust Programming
For more information about error handling, see About Configuration Manager Errors.
The example method has the following parameters:
Parameter
Type
Description
connection
Managed: WqlConnectionManager
VBScript: SWbemServices
A valid connection to the SMS Provider.
collectionID
Managed: String
VBScript: String
Unique auto-generated ID containing eight characters. For more information, see the CollectionID property of SMS_Collection Server WMI Class.
name
Managed: String
VBScript: String
An example collection property. The property value is modified in the code snippet.
comment
Managed: String
VBScript: String
An example collection property. The property value is modified in the code snippet.