To Modify a Collection

  1. Set up a connection to the SMS Provider.

  2. Get the specific collection instance by using the collection ID provided.

  3. Display the current property values (name and comment properties used as examples).

  4. 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.

Visual Basic Script  Copy Code
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
C#  Copy Code
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

  • 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.

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