Skip to content
SCCM ConfigMgr How to Remove Orphaned Collections

SCCM ConfigMgr How to Remove Orphaned Collections

Written By Anoop C Nair
Last Updated September 5, 2024
Posted In SCCM
SHARE

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.

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.

Patch My PC
SCCM ConfigMgr How to Remove Orphaned Collections - Fig.1
SCCM ConfigMgr How to Remove Orphaned Collections – Fig.1

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.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

Next

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.

Written by

Anoop C Nair is Workplace Technology solution architect with 25+ years of experience in global enterprise organizations such as JP Morgan, Capgemini, etc. Microsoft Certified Trainer. Microsoft MVP from 2015 onwards for consecutive 11+ years! He also conducts Intune and modern workplace tech training for enterprise organizations. He is Blogger, Speaker, and Founder of HTMD Community and HTMD Conference. His main focus is on Device Management technologies like Intune, Windows, Cloud PC. He writes about technologies like Intune, SCCM, Windows, Cloud PC, Windows, Entra, Microsoft Security.

Discussion · 1 comment

Join the discussion

Your email address will not be published. Required fields are marked *

Related guides

Intune

Windows 11 KB5101650 KB5099414 July 2026 Patch and 3 Zero Day Vulnerabilities and 570 Flaws

Key Takeaways Windows 11 KB5101650 KB5099414 July 2026 Patch and 3 Zero Day Vulnerabilities and 570 Flaws! In the July 2026 Patch, Microsoft introduced new features designed to improve the overall Windows experience. The update adds enhancements to Windows Update for more flexible update management and introduces Point-in-Time Restore, providing an additional recovery option for […]

AC Anoop C Nair 9 min read
Intune

2026 June KB5094126 KB5093998 Windows 11 Patch | 3 Zero Day Vulnerabilities and 200 Flaws

Key Takeaways 2026 June KB5094126 KB5093998 Windows 11 Patch | 3 Zero Day Vulnerabilities and 200 Flaws! The June 2026 Windows 11 Patch Tuesday update brings several improvements to File Explorer. It adds support for additional archive formats, including UU, CPIO, XAR, and NuGet Packages (NUPKG). The update also preserves View and Sort preferences in […]

AC Anoop C Nair 10 min read
Intune

2026 May KB5089549 KB5087420 Windows 11 Patch | 0 Zero Day Vulnerabilities and 120 Flaws

Key Takeaways The Windows 11 May 2026 Patch KB5089549 KB5087420 Update brings important security fixes, performance improvements, and reliability enhancements across the operating system. The update introduces new features such as Xbox Mode for gaming, File Explorer improvements, enhanced input and sharing experiences, better taskbar and Windows Hello reliability, and additional enterprise management capabilities for […]

AC Anoop C Nair 8 min read
SCCM

ConfigMgr 2603 Introduces New Early Update Enrollment Process

Key Takeaways In this post we are discussing the ConfigMgr 2603 Introduces New Early Update Enrollment Process. Microsoft has officially released Configuration Manager version 2603 to the Early Update Ring, giving organizations an opportunity to test upcoming improvements before the global production rollout. The release is targeted at enterprises running ConfigMgr version 2409 or later […]

AC Anoop C Nair 3 min read