Skip to content

Instantly share code, notes, and snippets.

@leeramsay
Last active July 29, 2016 11:41
Show Gist options
  • Save leeramsay/36e255d73c464cf2d91221c13b203c1d to your computer and use it in GitHub Desktop.
Save leeramsay/36e255d73c464cf2d91221c13b203c1d to your computer and use it in GitHub Desktop.
$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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment