To get the properties of a collection

  1. Set up a connection to the SMS Provider.

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

  3. Get the collection properties.


The following example method gets the properties of a collection.

For information about calling the sample code, see Calling Configuration Manager Code Snippets.

Visual Basic Script  Copy Code
Sub ReadCollectionProperties(connection, collectionID)	Dim collection	Dim statusText	Set collection = connection.Get("SMS_Collection.CollectionID='" & collectionID & "'")	WScript.Echo "Processing Collection - " & CStr(collection.CollectionID)	WScript.Echo "-- Name: " & collection.Name	WScript.Echo "-- Comment: " & collection.Comment	WScript.Echo "-- Members: " & CStr(collection.MemberCount)	statusText = "None"	Select Case collection.CurrentStatus	Case 1		statusText = "Ready"	Case 2		statusText = "Refreshing"	Case 5		statusText = "Awaiting Refresh"	End Select		WScript.Echo "-- Status: " & statusTextEnd Sub
C#  Copy Code
public void ReadCollectionProperties(WqlConnectionManager connection, string collectionID){ IResultObject collection = connection.GetInstance(string.Format("SMS_Collection.CollectionID='{0}'", collectionID)); string statusText = "None"; Console.WriteLine("Processing Collection - " + collectionID); Console.WriteLine("-- Name: " + collection["Name"].StringValue); Console.WriteLine("-- Comment: " + collection["Comment"].StringValue); Console.WriteLine("-- Members: " + collection["MemberCount"].IntegerValue.ToString()); switch (collection["CurrentStatus"].IntegerValue)	{ 	case 1:			statusText = "Ready"; 		break; 	case 2:			statusText = "Refreshing"; 		break; 	case 5:			statusText = "Awaiting Refresh"; 		break; 	default:			break; }	Console.WriteLine("-- Status: " + statusText);}

The example method has the following parameters:

Parameter Type Description


  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider.


  • Managed: String

  • VBScript: String

Unique auto-generated ID containing eight characters. For more information, see the CollectionID property of SMS_Collection Server WMI Class.

Compiling the Code

The C# example requires:









Robust Programming

For more information about error handling, see About Configuration Manager Errors.

See Also