Find Collection Membership for a Device with PowerShell

Here's a nice piece of PowerShell that will quickly tell you what collections a device is a member of.

Replace siteserver, sitecode and hostname with the relevant details. Hostname is obviously the name of the device you want to find collection membership for.

$Collections = (Get-WmiObject -ComputerName siteserver  -Namespace root/SMS/site_sitecode -Query "SELECT SMS_Collection.* FROM SMS_FullCollectionMembership, SMS_Collection where name = 'hostname' and SMS_FullCollectionMembership.CollectionID = SMS_Collection.CollectionID").Name

Write-Host $Collections