Skip to content

VBscript - problem with adding membershiprule to collection

Featured Replies

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

 

  • 2 weeks later...
  • Author

Problem is solved.The code is okay and working.

The script tried to create a query rule which is not limited to a collection (the same like a limitation to "All Systems"), but the executing account was not permitted to read values from "All Systems" collection.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.