top of page
  • Writer's pictureshishir kushawaha

MECM Cleanup Series: List orphan collections

Updated: Mar 26, 2023

Collections are likely the most crucial object to understand among all SCCM administration operations since they are the first point of contact for connecting the device with deployment and advertisement. After working on SCCM for a long time, there's a good chance you'll have "orphan" collections. If these collections are part of SCCM, they'll add extra work to your server's evaluation. Why waste your resources on these collections, especially if they have "incremental collection update"?

Identifying these collections can be challenging task. This is where PowerShell becomes really useful and saves lots of time. This PowerShell script will look for device collections that have no deployments or advertisements. You can also choose to filter the collections based on the number of members. So, if you need a collection with no members, this script will come in handy.


This PowerShell script will connect to SCCM and perform the following tasks:

  • The script will use the SCCM PowerShell module to collect a list of collections and their parameters, including the collection name, collection ID, and member count.

$COLLECTION_LIST = Get-CmCollection | Where-Object {$_.CollectionID -notlike 'SMS*' -and $_.CollectionType -eq '2'} | Select Name,MemberCount,CollectionID,IsReferenceCollection,LastMemberChangeTime
  • Next, the script will retrieve a list of all deployments in SCCM and extract the collections associated with each deployment.

$DEPLOYMENT_List=(Get-CMDeployment).CollectionID
  • The script will ask the user to specify the minimum number of members a collection should have to be included in the report. For instance, if the user sets the minimum number of members to 10, the script will only include collections in the report that have at least 10 members. If a collection has fewer than 10 members, it will not be included in the report.

write-host "Specify the minimum number of members a collection should have=" -foregroundcolor $inputcolor -nonewline
$MEMBER_COUNT=read-host 
  • The script will then compare the two lists and identify collections that are not present in any deployment collections list. These collections are considered "orphaned" collections.

$COMPARED_RESULT=(Compare-Object $DEPLOYMENT_List $COLLECTION_LIST.collectionid |? {$_.sideindicator -eq "=>"}).inputobject
  • Finally, the script will export the list of orphaned collections to an HTML page for easy viewing and analysis. This report will include the collection name, collection ID, and member count for each orphaned collection.

  • The report will also have an important column which is 'Lastmemberchangetime'. This is useful in deciding the cleanup of the collection. You can delete the collections which have older dates.


Please find the complete source code at GitHub. Please leave any comment for the script or any suggestions. #MECM #SCCM #CollectionCleanup #SCCMcleanup #advertisment #deployment


Note:

Please ensure that you thoroughly review the script before running it in your environment to ensure it aligns with your organization's policies and procedures.
Deletion of objects should be carefully handled.
Although some of the information is available through Management Insights section of MECM, however script is handy for customizations and automations.
1,296 views0 comments

Recent Posts

See All

PowerShell to list device collections membership

The collections membership feature for a device is already available in the SCCM admin Console. However here's a handy piece of PowerShell that will quickly tell you what collections a device is a par

Comentarios


bottom of page