Got orphaned collections in ConfigMgr?

This one goes back several years to when I was routinely writing code that used the ConfigMgr SDK (although in an odd coincidence, I was writing such code again yesterday).  It was pretty easy to run some buggy code that didn’t quite do what was intended, and as a result ConfigMgr might be left in an odd state.

One example of this: orphaned collections.  These exist in ConfigMgr, and if you look via WMI you can see them.  But they don’t exist in the console anywhere – they are invisible.  This would happen because those collections were not “rooted” to the top-level collection called “COLLROOT” (or any other collection, if you build collection hierarchies).

Other than “buggy code”, how else could these orphaned collections happen?  Good question, hard to say.

So how do you fix these?  Well, simple:  You “re-root” them by creating a new SMS_CollectToSubCollect WMI instance that says “this collection is a subcollection of COLLROOT”.  A long time ago, I wrote a script to do this.  After enough digging around, I found it again, so I’ll provide it here:

Set services = Getobject("winmgmts://YOURSERVER/root/sms/site_XXX")

' Just in case we need to re-root a collection, get the class instance
Set theClass = services.Get("SMS_CollectToSubCollect")

' Get a list of collections.  Make sure each one has a parent.  If not, connect it to COLLROOT.
Set collList = services.ExecQuery("select * from SMS_Collection where CollectionID <> 'COLLROOT' ")
For each c in collList

    ' WScript.Echo "Checking " & c.CollectionID

    ' See if this collection is already associated with the root collection.  If not, fix it.
    Set result = services.ExecQuery("select * from SMS_CollectToSubCollect where subCollectionID = """ & c.CollectionID & """")
    If result.Count = 0 Then
        WScript.Echo "No parent found for " & c.CollectionID

        Set theRelationship = theClass.SpawnInstance_()
        theRelationship.parentCollectionID = "COLLROOT"
        theRelationship.subCollectionID = c.CollectionID
        Set path = theRelationship.Put_
        Set path = Nothing
        Set theRelationship = Nothing

    WScript.Echo "Added " & c.CollectionID & " (" & c.Name & ") to the root collection"

    End If
    Set result = Nothing


Paste this into a text file, change the server name (from “YOURSERVER”) and site code (from “XXX”), save it as “ReRoot.vbs”, and run it using “cscript.exe ReRoot.vbs”.  It will check every collection, and if it finds one that is orphaned, it will “re-root” it to to the root collection, telling you what collection (ID and name) was fixed.  After the script is finished, you can find the “re-rooted” collections in the admin console, and you can decide what to do with them from there.

Comments (5)
  1. Neil Clinch says:

    I figured it out....

    $CollectionList = Get-WmiObject -Namespace 'rootsmssite_<SITECODE>' -Class SMS_Collection -ComputerName <Site Server Name>

    $Collection = $CollectionList | where {$_.CollectionID -eq 'XXX00064'}


    not real pretty but it works...

  2. Neil Clinch says:

    Ok I have this problem in SCCM 2012.. there are no sub collects in SCCM 2012 so how do I whack these ophaned colletions.  I think the orphans were created as part of a migration from or old SCCM site.

  3. showbox says:

    Thanks for the great info. I really loved this. I would like to apprentice at the same time as you amend your web site, how could i subscribe for a blog site?
    For more info on showbox please refer below sites:
    Latest version of Showbox App download for all android smart phones and tablets. - It’s just 2 MB file you can easily get it on your android device without much trouble. Showbox app was well designed application for android to watch movies and TV shows, Cartoons and many more such things on your smartphone.
    For showbox on iOS (iPhone/iPad), please read below articles:
    Showbox for PC articles:
    There are countless for PC clients as it is essentially easy to understand, simple to introduce, gives continuous administration, effectively reasonable. it is accessible at completely free of expense i.e., there will be no establishment charges and after establishment
    it doesn't charge cash for watching films and recordings. Not simply watching, it likewise offers alternative to download recordings and motion pictures. The accompanying are the strides that are to be taken after to introduce Showbox application on Android.
    The above all else thing to be done is, go to the Security Settings on your Android telephone, Scroll down and tap on 'Obscure sources'.

  4. aw says:

    hai, I just want to tell you that I am just very new to blogs and seriously loved this website. More than likely I’m planning to bookmark your blog post .
    You amazingly come with really good posts. Thanks a lot for sharing your blog Microsoft.

Comments are closed.

Skip to main content