It is sometimes useful to get a list of members for an SMS collection. For example, you may want a list of computers that an advertisement is distributed to. Because an advertisement is distributed to an SMS collection, enumerating the collection would get the list of computers.

In SMS, a resource is stored in a collection by instances of the SMS_FullCollectionMembership class. An instance of this class has a collection identifier (CollectionID) and a resource identifier (ResourceID).

The following example gets the name of the Windows 2003 Server systems by retrieving instances that match the collection identifier for the Windows Server 2003 collection (SMS0001). The collection is then enumerated to display the matching computer names.

Example

On Error Resume Next
Dim objSWbemServices
Dim ProviderLoc
Dim Location
Dim colQueryCollectionResults
Dim ObjResult
Dim objQuery
Dim colQueryResults

Set ProviderLoc = GetObject("winmgmts:{impersonationLevel=impersonate}!root/sms:SMS_ProviderLocation")

If err.number<>0 Then
	wscript.echo "Couldn't get SMS Provider"
	wscript.quit
End If

For Each Location In ProviderLoc.Instances_
	 If Location.ProviderForLocalSite = True Then
		Set objSWbemServices = GetObject("winmgmts:" & Location.NamespacePath)
	Exit For
   End If
Next

'Query Collection.
Set colQueryCollectionResults=objSWbemServices.ExecQuery("SELECT * FROM SMS_FullCollectionMembership WHERE CollectionID='SMS00001'" )

If err.number<>0 Then
	wscript.echo "Couldn't get Collection"
	wscript.quit
End If

'Run query.
wscript.echo "Collections"
wscript.echo "----------------------------------"
 
For Each objResult In colQueryCollectionResults
	wscript.echo "	 " + objResult.Name
Next
If colQueryCollectionResults.Count=0 Then
	wscript.echo "	no query results"
End If

Compiling the Code

  • Requires Windows 2000 Server SP2 or later.

  • You must run this sample on an SMS 2003 site server.

See Also