Jump to content


SRed

List Collection Membership with Powershell

Recommended Posts

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?

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...