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?