Getting all Members of all Collections in a Folder in ConfigMgr

In our SCCM 2012 environment, we have a subfolder of device collections that are used for Software Updates.  I wanted to get a list of all the members of the different collections in that folder.  I saw a recent post by Kaido Järvemets on how to easily list folder objects using Powershell, so I decided to implement that code into a script that exports all the collections and their members in a ConfigMgr folder you specify, into a text file.

You need to get the ContainerNodeID from WMI as Kaido describes in his post, then add that and your site code to the script.

I want all the collections in the ‘Software Updates’ folder:



I run the script…


Then I get a text file containing all the collections with their members. 🙂

$SiteCode = "PS1"
$FolderID = 16777221 # Use the WMI tool to get the FolderID

Write-Host "Getting Folder Name of Folder ID $FolderID"
$FolderName = Get-WmiObject -Namespace "ROOT\SMS\Site_$SiteCode" `
-Query "select * from SMS_ObjectContainerNode where ContainerNodeID='$FolderID'" | Select Name
$FolderName = $FolderName.Name
Write-Host "Getting Collections from '$FolderName'"
$CollectionsInSpecficFolder = Get-WmiObject -Namespace "ROOT\SMS\Site_$SiteCode" `
-Query "select * from SMS_Collection where CollectionID is
in(select InstanceKey from SMS_ObjectContainerItem where ObjectType='5000'
and ContainerNodeID='$FolderID') and CollectionType='2'"

$Collections = $CollectionsInSpecficFolder.Name

Write-host "Getting collection members for:"

Foreach ($Collection in $Collections) {

$Col = Get-CMDeviceCollection -Name $Collection | Select Name, Comment, CollectionID, MemberCount
$Members = Get-CMDevice -CollectionName $Collection | Select Name | Sort Name
$Col,"**Members** ",$Members | ft -AutoSize | Out-File -FilePath C:\Scripts\Staging\SoftwareUpdatesMembers.txt -Append

Invoke-Item C:\Scripts\Staging\SoftwareUpdatesMembers.txt

Quick Tip: Creating USB Standalone Media on a VMWare VM

Using USB media for a Standalone OS deployment is a great idea – you have greater storage capacity than a DVD, and the read speed is quicker, resulting in easier and quicker deployments.  But what if your SCCM server is a VM?  You can’t physically connect a USB storage device to the server, but you can use USB passthrough on your Virtual Host.  This is available in Hyper-V on Windows Server 2012 R2, and since ESXi4.1 on VMWare.  However, since vSphere 5.0, you can use also use a ‘client-connected’ USB device.  This means if you don’t have access to the physical host your VM is running on, maybe it’s in a cloud datacenter, on another geographical site, or you’re just feeling lazy, you can still passthrough a USB device from your client computer to the VM – a very useful feature indeed!

Add a USB Controller

The first thing you need to do is add a USB controller to your VM.  Edit the settings of your VM, go to ‘New Device’ and add the ‘USB Controller’.  Click OK to save the settings.

(Screenshots from vSphere Web Client)


Add the USB Device

Then in the ‘Summary’ page of the VM, in the ‘VMWare Hardware’ section, you’ll see ‘USB Devices’.  Click ‘Connect client device’ and choose your locally connected USB storage device.

summary1Once connected, refresh the page and you’ll see the newly connected USB device.

summary2Create your Standalone Media

Now you can go to the VM and you’ll see the mapped USB device.  You can go ahead and use the Task Sequence media wizard to create your USB Standalone media.  Here’s mine from Disk Management after creating the media: