How to Modify a Collection
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);}
The example method has the following parameters:
Parameter |
Type |
Description |
---|---|---|
connection |
|
A valid connection to the SMS Provider. |
collectionID |
Unique auto-generated ID containing eight characters. For more information, see the CollectionID property of SMS_Collection Server WMI Class. |
|
name |
An example collection property. The property value is modified in the code snippet. |
|
comment |
An example collection property. The property value is modified in the code snippet. |
Compiling the Code
The C# example requires:
Namespaces
System
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
mscorlib
Robust Programming
For more information about error handling, see About Configuration Manager Errors.
See Also
Configuration Manager Collections
SMS_Collection Server WMI Class