Skip to content

List Collection Membership with Powershell

Featured Replies

Hey all,

 

I'm looking to use Powershell to list all collections a particular Computer is a member of.

 

I have a way of listing all the members of a particular collection, but I don't have the reverse, which would be listing all the collections a member is in. I'll post what I've got.

 

PS C:\> (get-command Get-CollectionMember).ScriptBlock
Param($CollName)
$SiteCode="ATL"
  $SCCMServer="SCCM"

# Get a list of collections and find the object to build the collection list.
$Collection = Get-WmiObject -ComputerName $SCCMServer  -Namespace `
"root\sms\site_$SiteCode" -Class 'SMS_Collection'
$MyCollection = $Collection | Where-Object { $_.Name -eq $CollName }
# Grab the Resource ID of the collection
$MyCollectionMembers = Get-WmiObject  -ComputerName $SCCMServer -Namespace `
"root\sms\site_$SiteCode"  -Query "select * from SMS_CM_RES_COLL_$($MyCollection.CollectionID)"
#Echo member of the collections to screen
Foreach ($member in $MyCollectionMembers) {
  $oldErrCount = $error.Count
 $Name = $member.Name.ToString()
$Name
 }

 

I found this code somewhere online and modified it to fit. Now, this will list all of the members of a specified collection, but can't be used to find all the collections a member is in. Anyone have any ideas?

I don't know much about Powershell but If you want to script, you can create one that queries the DB directly instead of using a WMI query.

 

The table is dbo.CollectionMembers. You can search it by name or Machine ID but ID would give more exact if you recently imaged same named systems where the old entry still exists.

  • Author

@Kaido, can you download the script from that site? I can't.

  • 6 months later...

Hi Kaido, the link is broken again. Any chance of a fix? Thanks

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.