AddMembershipRule Method in Class SMS_Collection
The AddMembershipRule WMI class instance method adds a new rule to the CollectionRules property of SMS_Collection. This method can also be used to modify a membership rule.
The following syntax is simplified from MOF code and is intended to show you the definition of the method.
sint32 AddMembershipRule(
[in] SMS_CollectionRule collectionRule,
[out] uint32 QueryID
);
Parameters
collectionRule
Data type: SMS_CollectionRule
Qualifiers: InA direct rule (SMS_CollectionRuleDirect) or query rule (SMS_CollectionRuleQuery) instance.
QueryID
Data type: uint32
Qualifiers: OutSMS-generated query identifier if the rule is a query rule; if not, it is zero (0). Use QueryID to modify or delete a query membership rule.
Return Values
The AddMembershipRule method returns a sint32 which is always zero (0).
Example Code
The following example shows you how to add a direct rule and a query rule to a collection.
Dim instCollection As SWbemObject 'Instance of SMS_Collection Dim clsQueryRule As SWbemObject 'SMS_CollectionRuleQuery class method Dim instQueryRule As SWbemObject 'Instance of SMS_CollectionRuleQuery Dim instDirectRule As SWbemObject 'Instance of SMS_CollectionRuleDirect Dim Query As String Dim ValidQuery As Boolean Dim QueryID As Long Set instCollection = Services.Get("SMS_Collection.CollectionID=""<collectionid>""") 'Create the direct rule. Set instDirectRule = Services.Get("SMS_CollectionRuleDirect").SpawnInstance_ instDirectRule.ResourceClassName = "SMS_R_System" instDirectRule.ResourceID = <resourceid> instDirectRule.RuleName = "MyDirectRule" 'Add the direct rule to the collection. instCollection.AddMembershipRule instDirectRule 'Always validate your query before adding a query rule to the collection. Query = "SELECT * FROM SMS_R_System WHERE SystemRoles = 'SMS Client Access Point'" Set clsQueryRule = Services.Get("SMS_CollectionRuleQuery") ValidQuery = clsQueryRule.ValidateQuery(Query) If ValidQuery Then 'Create the query rule. Note that you use these same steps to 'modify an existing query rule, except that you set the QueryID property 'value to the query rule you want to modify. Set instQueryRule = clsQueryRule.SpawnInstance_ instQueryRule.QueryExpression = Query instQueryRule.RuleName = "MyQueryRule" 'Add the query rule to the collection. You only need to specify QueryID if 'you want to capture the identifier for use later (you use QueryID to 'update or delete the rule.) instCollection.AddMembershipRule instQueryRule, QueryID End If 'After you have added all the membership rules, call RequestRefresh to initiate 'the collection evaluator. instCollection.RequestRefresh False
Remarks
To delete a membership rule, the query number is needed to set the QueryID value.
To add multiple membership rules, use the AddMembershipRules Method in Class SMS_Collection.
See Also
AddMembershipRules Method in Class SMS_Collection, SMS_Collection, SMS_CollectionRuleDirect, SMS_CollectionRuleQuery, ValidateQuery Method in Class SMS_CollectionRuleQuery