Last week I saw one blog post how to list specific folder objects and I believe that actually there is much easier way to list the objects in specific folder. First we need to figure out the ContainerNodeID which is the folder unique ID.
We have several ways to find out the folder unique ID, for example we can run the ConfigMgr Admin console in developer mode or we can use a WMI tool. There are different WMI tools that you can find from the internet or you can simple use the WBEMTEST tool also which is already built-in in Windows. In this case I´m using our Coretech WMI and PowerShell Explorer tool.
So let’s assume that you want to modify collections in OSD folder. In this case I have two collections in OSD folder.
1. Run the Coretech WMI and PowerShell Explorer tool and connect to ROOT\SMS\Site_PS1 namespace.
2. Type into Filter textbox ObjectCon and select SMS_ObjectContainerNode WMI class
3. Select Query tab and execute the following WQL query:
Select ContainerNodeID,Name,ObjectType from SMS_ObjectContainerNode
In this output you should see the folder name and the unique ID (ContainerNodeID). Object type 5000 means a Device Collection. You can check additional values from here. Write down the ContainerNodeID property value and then open PowerShell ISE.
4. Write the following code
$FolderID = 16777224 # Use the WMI tool to get the FolderID
$CollectionsInSpecficFolder = Get-WmiObject -Namespace "ROOT\SMS\Site_PS1" `
-Query "select * from SMS_Collection where CollectionID is in(select InstanceKey from SMS_ObjectContainerItem where ObjectType='5000' and ContainerNodeID='$FolderID') and CollectionType='2'"
5. Execute the code and it should list all the Collection Names in OSD folder.
As you see you can query the folder objects only with one query and no need for multiple queries.Share