Advertisement
Old-Lost

Get SCCM Collection Members

Apr 5th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $SiteServer = 'server'
  2. $SiteCode = 'XXX'
  3. $CollectionName = 'DeviceColl*'
  4.  
  5. $Collections = Get-WmiObject -ComputerName $SiteServer -Namespace  "ROOT\SMS\site_$SiteCode" -Class SMS_Collection | where {$_.Name -like "$CollectionName"}
  6.  
  7. foreach ($Collection in $Collections){
  8.     $SMSClients = Get-WmiObject -ComputerName $SiteServer -Namespace  "ROOT\SMS\site_$SiteCode" -Query "SELECT * FROM SMS_FullCollectionMembership WHERE CollectionID='$($Collection.CollectionID)' order by name" | select *
  9.     foreach ($SMSClient in $SMSClients){
  10.         $ClientName = $SMSClient.Name
  11.         $ClientMAC = (Get-WmiObject -Class SMS_R_SYSTEM -ComputerName $SiteServer -Namespace root\sms\site_$SiteCode | where {$_.Name -eq "$ClientName"}).MACAddresses
  12.         $SMSClient.Name + ", " + $ClientMAC + ", " + $Collection.Name | out-file -append C:\list.txt
  13.     }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement