PowerShell Script to locate SCCM objects in SCCM console

2 minute read

There are many object types in SCCM that supports folders in the console. Even though the object can be easily located using the search function, often we need to find out which folder does a particular object (i.e. package, advertisement, etc) reside.  At work, we use folders to separate objects for different business units and differnet IT service providers. Therefore, there are many times I need to find out where exactly is the object located.

I wrote this script today called Locate-SCCMObject.PS1

Syntax: .\Locate-SCCMObject <SCCM Central Site Server> <SCCM Object ID>:


Using the script:


From SCCM Console:


The output of the script shows the object type and the path in the console, in this case, it’s a software package located under Application\Microsoft Office folder.

Source Code:

# AUTHOR:	Tao Yang
# DATE:		20/05/2011
# Name:		Locate-SCCMObject.PS1
# Version:	1.0
# COMMENT:	Use this script to locate a SCCM object in SCCM Console. Please note it does not work for SCCM collections.
# Usage:	.\Locate-SCCMObject.ps1 &lt;SCCM Central Site Server&gt; &lt;SCCM Object ID&gt;


Function Get-SCCMObjectType ($ObjType)
	Switch ($objType)
		2 {$strObjType = "Package"}
		3 {$strObjType = "Advertisement"}
		7 {$strObjType = "Query"}
		8 {$strObjType = "Report"}
		9 {$strObjType = "Metered Product Rule"}
		11 {$strObjType = "ConfigurationItem"}
		14 {$strObjType = "Operating System Install Package"}
		17 {$strObjType = "State Migration"}
		18 {$strObjType = "Image Package"}
		19 {$strObjType = "Boot Image Package"}
		20 {$strObjType = "TaskSequence Package"}
		21 {$strObjType = "Device Setting Package"}
		23 {$strObjType = "Driver Package"}
		25 {$strObjType = "Driver"}
		1011 {$strObjType = "Software Update"}
		2011 {$strObjType = "Configuration Item (Configuration baseline)"}
		default {$strObjType = "Unknown"}
	Return $strObjType

Function Get-ConsolePath ($CentralSiteProvider, $CentralSiteCode, $SCCMObj)
	$ContainerNodeID = $SCCMObj.ContainerNodeID
	$strConsolePath = $null
	$bIsTopLevel = $false
	$objContainer = Get-WmiObject -Namespace root\sms\site_$CentralSiteCode -Query "Select * from SMS_ObjectContainerNode Where ContainerNodeID = '$ContainerNodeID'" -ComputerName $CentralSiteProvider
	$strConsolePath = $objContainer.Name
	$ParentContainerID = $objContainer.ParentContainerNodeID
	if ($ParentContainerID -eq 0)
		$bIsTopLevel = $true
	} else {
			$objParentContainer = Get-WmiObject -Namespace root\sms\site_$CentralSiteCode -Query "Select * from SMS_ObjectContainerNode Where ContainerNodeID = '$ParentContainerID'" -ComputerName $CentralSiteProvider
			$strParentContainerName = $objParentContainer.Name
			$strConsolePath = $strParentContainerName +"`\"+$strConsolePath
			$ParentContainerID = $objParentContainer.ParentContainerNodeID
			Remove-Variable objParentContainer, strParentContainerName
			if ($ParentContainerID -eq 0) {$bIsTopLevel = $true}

		} until ($bIsTopLevel -eq $true)
	Return $strConsolePath
$objSite = Get-WmiObject -ComputerName $CentralSiteServer -Namespace root\sms -query "Select * from SMS_ProviderLocation WHERE ProviderForLocalSite = True"
$CentralSiteCode= $objSite.SiteCode
$CentralSiteProvider = $objSite.Machine
$SCCMObj = Get-WmiObject -Namespace root\sms\site_$CentralSiteCode -Query "Select * from SMS_ObjectContainerItem Where InstanceKey = '$objID'" -ComputerName $CentralSiteProvider
If ($SCCMObj -eq $null)
	Write-Host "SCCM Object with ID $objID cannot be found!" -ForegroundColor Red
} else {
$strObjType = Get-SCCMObjectType $SCCMObj.ObjectType
$strConsolePath = Get-ConsolePath $CentralSiteProvider $CentralSiteCode $SCCMObj
Write-Host "Object Type`: $strObjType" -ForegroundColor Yellow
Write-Host "Console Path`: $strConsolePath" -ForegroundColor Yellow

This script should work for all objects that support folders. However, it does not work for collections. Collections do not support folders, but you can have sub collections and linked collections. I have written another script to locate collections. It is posted here.

Leave a comment