1: ' Set up a connection to the local provider.
2: Set swbemLocator = CreateObject("WbemScripting.SWbemLocator")
3: Set swbemconnection= swbemLocator.ConnectServer(".", "root\sms")
4: Set providerLoc = swbemconnection.InstancesOf("SMS_ProviderLocation")
5:
6: For Each Location In providerLoc
7: If location.ProviderForLocalSite = True Then
8: Set swbemconnection = swbemLocator.ConnectServer(Location.Machine, "root\sms\site_" + Location.SiteCode)
9: Exit For
10: End If
11: Next
12:
13: Call CreateStaticCollection(swbemconnection, "ICT00056", "Test Collection", "Your comments here", true, "SMS_R_UserGroup", "9006")
14:
15:
16: Sub CreateStaticCollection(connection, existingParentCollectionID, newCollectionName, newCollectionComment, ownedByThisSite, resourceClassName, resourceID)
17:
18: ' Create the collection.
19: Set newCollection = connection.Get("SMS_Collection").SpawnInstance_
20: newCollection.Comment = newCollectionComment
21: newCollection.Name = newCollectionName
22: newCollection.OwnedByThisSite = ownedByThisSite
23:
24: ' Save the new collection and save the collection path for later.
25: Set collectionPath = newCollection.Put_
26:
27: ' Define to what collection the new collection is subordinate.
28: ' IMPORTANT: If you do not specify the relationship, the new collection will not be visible in the console.
29: Set newSubCollectToSubCollect = connection.Get("SMS_CollectToSubCollect").SpawnInstance_
30: newSubCollectToSubCollect.parentCollectionID = existingParentCollectionID
31: newSubCollectToSubCollect.subCollectionID = CStr(collectionPath.Keys("CollectionID"))
32:
33: ' Save the subcollection information.
34: newSubCollectToSubCollect.Put_
35:
36: ' Create the direct rule.
37: Set newDirectRule = connection.Get("SMS_CollectionRuleDirect").SpawnInstance_
38: newDirectRule.ResourceClassName = resourceClassName
39: newDirectRule.ResourceID = resourceID
40:
41: ' Add the new query rule to a variable.
42: Set newCollectionRule = newDirectRule
43:
44: ' Get the collection.
45: Set newCollection = connection.Get(collectionPath.RelPath)
46:
47: ' Add the rules to the collection.
48: newCollection.AddMembershipRule newCollectionRule
49:
50: ' Call RequestRefresh to initiate the collection evaluator.
51: newCollection.RequestRefresh False
52:
53: End Sub
54:
55: