Search the Community
Showing results for tags 'membershiprule'.
-
Hello at all, I’m working on a script which creates a SCCM collection and appends a collection rule. The function createCollection creates and moves the collection without any problems. The collection rule object is also created without any error codes, but at adding the collection rule (newCollection.AddMembershipRule newCollectionRule) I get a “general error”. Has anybody an idea how to fix this problem? Function createCollection(collectionName) Dim validQuery, queryExpr ' creates the collection. Set newCollection = objSccm.Get("SMS_Collection").SpawnInstance_() newCollection.Name = collectionName newCollection.OwnedByThisSite = True newCollection.Comment = "Comment" Set collectionPath = newCollection.Put_ ' Attempts to obtain the collection ID of the newly created collection. Set Collection = objSccm.ExecQuery ("select * from SMS_Collection where Name='" & collectionName & "'") For each objCollection in Collection strCollectionID=objCollection.CollectionID Next If strCollectionID = "" Then Wscript.Echo "Unable to obtian a collection ID for the newly created collection." WScript.Quit Else ' Attempts to move the newly created collection into the desired parent collection. Set newCollectionRelation = objSccm.Get("SMS_CollectToSubCollect").SpawnInstance_() newCollectionRelation.parentCollectionID = strParentCollectionID newCollectionRelation.subCollectionID = strCollectionID newCollectionRelation.Put_ End If 'Attempts to create and add the query rule group to the collection! Set stdQuery = objSccm.Get("SMS_CollectionRuleQuery") validQuery = stdQuery.ValidateQuery(queryExpr) If validQuery Then Set newCollectionRule = stdQuery.SpawnInstance_ newCollectionRule.QueryExpression = queryExpr newCollectionRule.RuleName = "Rulename" Set newCollection = objSccm.Get(collectionPath.RelPath) newCollection.AddMembershipRule newCollectionRule newCollection.RequestRefresh False End If End Function
- 1 reply
-
- VBscript
- collection
-
(and 2 more)
Tagged with: