SCCM ConfigMgr How to Remove Orphaned Collections. This one goes back several years to when I routinely wrote code using the ConfigMgr SDK.
It was easy to run some buggy code that didn’t quite do what was intended so that ConfigMgr might be left in an odd state.
Table of Contents
How to Remove Orphaned Collections
One example is orphaned collections. These exist in ConfigMgr, and if you look at them 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). SCCM ConfigMgr How to Remove Orphaned Collections.
- How To Disable SCCM Application Deployment | ConfigMgr | MEMCM
- Fix Report Server Cannot Open A Connection Error ConfigMgr | SCCM
Besides “buggy code,” how else could these orphaned collections happen? That’s a good question; it’s hard to say. SCCM ConfigMgr: How to Remove Orphaned Collections.
So how do you fix these? Well, it is 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.CollectionIDSet theRelationship = theClass.SpawnInstance_()
theRelationship.parentCollectionID = “COLLROOT”
theRelationship.subCollectionID = c.CollectionID
Set path = theRelationship.Put_
Set path = Nothing
Set theRelationship = NothingWScript.Echo “Added ” & c.CollectionID & ” (” & c.Name & “) to the root collection”
End If
Set result = NothingNext
Paste this into a text file, change the server name (from “YOUR SERVER”) 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 orphaned, it will “re-root” it 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 decide what to do with them.
We are on WhatsApp. To get the latest step-by-step guides and news updates, Join our Channel. Click here –HTMD WhatsApp.
Author
Anoop C Nair is Microsoft MVP! He is a Device Management Admin with more than 20 years of experience (calculation done in 2021) in IT. He is a Blogger, Speaker, and Local User Group HTMD Community leader. His primary focus is Device Management technologies like SCCM 2012, Current Branch, and Intune. He writes about ConfigMgr, Windows 11, Windows 10, Azure AD, Microsoft Intune, Windows 365, AVD, etc.
Is there any sql queries for this same to find out orphaned collections