<# 
2 .SYNOPSIS 
3 Get the collection membership of a configuration manager client device or computer. 
4  
5 .DESCRIPTION 
6 Get the collection membership of a configuration manager client device or computer. 
7 This function will query System Center Configuration manager for a given computer name 
8 and return the collections for which it is a member. 
9  
10 .PARAMETER ComputerName 
11 Provide a computer name. 
12  
13 .PARAMETER SiteServer 
14 Specify the name or FQDN of your SCCM site server. By default it gathers the site server 
15 from the computer from which the function is called. 
16  
17 .PARAMETER SiteCode 
18 Specify the site code of your SCCM environment. By default it gathers the site code 
19 from the computer from which the function is called. 
20  
21 .PARAMETER Credential 
22 Provide a credential object for accessing the site server. 
23  
24 .EXAMPLE 
25 Get-CMClientDeviceCollectionMembership  
26  
27 Gets the collection membership of the local host. 
28  
29 .EXAMPLE 
30 Get-CMClientDeviceCollectionMembership -Computer DESKTOP01 
31  
32 Gets the collection membership of DESKTOP01 
33  
34 .EXAMPLE 
35 Get-CMClientDeviceCollectionMembership -Computer DESKTOP01 -Summary 
36  
37 Gets the collection membership of DESKTOP01 in a summary format. 
38  
39 .NOTES 
40 Created by: Jason Wasser @wasserja 
41 Modified: 6/8/2017 10:49:50 AM  
42 #> 
function Get-CMClientDeviceCollectionMembership { 
    [CmdletBinding()] 
     param ( 
         [string]$ComputerName = $env:COMPUTERNAME, 
         [string]$SiteServer = (Get-WmiObject -Namespace root\ccm -ClassName SMS_Authority).CurrentManagementPoint, 
         [string]$SiteCode = (Get-WmiObject -Namespace root\ccm -ClassName SMS_Authority).Name.Split(':')[1], 
         [switch]$Summary, 
         [System.Management.Automation.PSCredential]$Credential = [System.Management.Automation.PSCredential]::Empty 
     ) 
 
 
 begin {} 
 process { 
     Write-Verbose -Message "Gathering collection membership of $ComputerName from Site Server $SiteServer using Site Code $SiteCode." 
     $Collections = Get-WmiObject -ComputerName $SiteServer -Namespace root/SMS/site_$SiteCode -Credential $Credential -Query "SELECT SMS_Collection.* FROM SMS_FullCollectionMembership, SMS_Collection where name = '$ComputerName' and SMS_FullCollectionMembership.CollectionID = SMS_Collection.CollectionID" 
     if ($Summary) { 
         $Collections | Select-Object -Property Name,CollectionID 
     } 
     else { 
         $Collections     
     } 
      
 } 
 end {} 
 } 

 #          Get-CMClientDeviceCollectionMembership -ComputerName w2012a  | Select name,LimitToCollectionName

