How to Modify a Collection
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
andcomment
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 |
- 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
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for