Share via

Powershell Command for SCCM

Balayuvaraj M 56 Reputation points
2022-07-25T10:55:09.27+00:00

In SCCM how to get the list of collection name or collection id for the a particular server from powershell

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

2 answers

Sort by: Most helpful
  1. Limitless Technology 40,106 Reputation points
    2022-07-27T07:16:18.107+00:00

    Hello,

    I think the better combination would be:

    Get-CMCollectionMember
    https://learn.microsoft.com/en-us/powershell/module/configurationmanager/get-cmcollectionmember?view=sccm-ps

    Get-Content "C:\Temp\ServerList.txt" | foreach {Get-CMDevice} | Export-Csv -Force -NoTypeInformation "c:\temp\sccmcollectioninfo.csv"

    or :

    $DeviceName = "your device"
    $SiteServer = "site server"
    $SiteCode ="site name"
    (Get-WmiObject -ComputerName $SiteServer -Namespace root/SMS/site_"$SiteCode" -Query "SELECT SMS_Collection.* FROM SMS_FullCollectionMembership, SMS_Collection where name = '$DeviceName' and SMS_FullCollectionMembership.CollectionID = SMS_Collection.CollectionID")

    ------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer--

    Was this answer helpful?

    0 comments No comments

  2. DaveK 1,871 Reputation points
    2022-07-25T13:10:07.507+00:00

    Hi, I'm not 100% sure on what your asking for here to I'll take the easy answer first, if your looking to find a list of the collections for a particular sccm endpoint server then

    Get-CMCollection should do the trick, without a collection name provided its documentation says it will return all collections - https://learn.microsoft.com/en-us/powershell/module/configurationmanager/get-cmcollection?view=sccm-ps

    You'll need to have the PS drive setup for your SCCM site to use the SCCM powershell commands.

    If your wanting to get a list of collections that a specific server is a member of something like this will allow you to return all collections its a member of

    $SiteServer = [YOUR_SITE_SERVER]  
    $SiteCode = [YOUR_SITE_CODE]  
    $Hostname = [HOSTNAME]  
      
    $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  
    

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.