Get Computers in SCCM Collection

This script will gather all computers in a specified SCCM collection.  The wmi method is used to connect to the SCCM Server, get the collection information, and then get the memebers.  All of the members will be in $SMSMembers.  $SiteServer = 'vadenmpsrvp01'$SiteCode = 'S01'$Coll

 
 
 
 
 
4.5 Star
(6)
Add to favorites
System Center
10/23/2012
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Output of machine name is in different format
    1 Posts | Last post March 09, 2017
    • The Output of Machine Name for below script is in different format like @{ABCDEF12}
      please provide the formatting part.
      
      Thanks
      
      $SiteServer = 'SERVER NAME 
      $SiteCode = 'SITE CODE' 
      $CollectionName = 'NAME OF COLLECTION' 
      $cred = Get-credential 
      #Retrieve SCCM collection by name 
      $Collection = get-wmiobject -ComputerName $siteServer -NameSpace "ROOT\SMS\site_$SiteCode" -Class SMS_Collection -Credential $cred  | where {$_.Name -eq "$CollectionName"} 
      #Retrieve members of collection 
      $SMSMemebers = Get-WmiObject -ComputerName $SiteServer -Credential $cred -Namespace  "ROOT\SMS\site_$SiteCode" -Query "SELECT * FROM SMS_FullCollectionMembership WHERE CollectionID='$($Collection.CollectionID)' order by name" | select Name
  • An alternative
    1 Posts | Last post August 05, 2013
    • Here's what I came up with.  It does require you to use the ConfigMgr 2012 SP1 module which you need to run in (x86) mode:
      
      function Get-CollectionMembers{
      [CmdletBinding()]
      param(
          [Parameter(Mandatory=$True)]
          [String]$CollectionName
      )
      
      $CollectionID = Get-CMDeviceCollection -Name $CollectionName | Select CollectionID
      $ComputerList = Get-CMDevice -CollectionId $CollectionID.CollectionID | Select -Property Name 
      
      ForEach ($ComputerObject In $ComputerList){
      
      Get-ADComputer -Identity $ComputerObject.Name -Properties CanonicalName | Select Name,CanonicalName
      
      }
      }