locked
Querying SCCM for Collection rules by Powershell RRS feed

  • Question

  • I am trying to get a list of collections rules applied to a particular collection, in sccm. I have psbase property of a collectionrules which contains the names of the collectionrules. How do I access those collections, using powershell?
    Wednesday, January 21, 2009 10:03 PM

Answers

All replies

  • Hello,

    You can use $var = [WMI] \\.\root\sms\site_xxx:SMS_Collection.CollectionID='ZZZ'

    with xxx = sitecode and zzz=collectionID

    That will return you an object with CollectionRules property that you don't have with a gwmi query.

    BL

    Monday, October 25, 2010 3:44 PM
  • In SCCM 2012, this data isn't immediately apparent:

    But see what happens when using the expand switch:

    Get-CMDeviceCollection | select -expand collectionrules

    Another example below.  This assumes Collections don't have multiple rules.

    Get-CMDeviceCollection | ? {$_.CollectionRules.RuleName -ne $null} | % {Get-CMDeviceCollectionQueryMembershipRule -CollectionID $_.CollectionID -RuleName $_.CollectionRules.RuleName}

    BTW, I found that in CU2 (maybe CU1) this issue seems to have been resolved.  However CollectionRules seems to be case sensitive.

    This works: Get-CMDeviceCollection | select -expand CollectionRules

    This does not: Get-CMDeviceCollection | select -expand collectionrules




    Mike Crowley | MVP
    My Blog -- Planet Technologies



    • Edited by Mike Crowley Wednesday, July 17, 2013 7:08 PM added more
    Wednesday, July 17, 2013 6:51 PM
  • Hi,

    I am trying to do the same thing and I can see how your script runs but I need a list either text or csv with the collection name or ID along with the corresponding queries. Do you know how to do this?

    Thanks

    Monday, June 23, 2014 3:19 PM
  • A collection can have multiple query-based membership rules.  Each of those rules can have multiple queries.  CSVs are 2 dimensional, and don't support this type of nesting.  You could simply take the first query from the first rule, but depending on how the collections are defined, there could be missing information.

    XML on the other hand, can support this type of nesting.

    I haven't tested this (use at your own risk), but this could be the general idea, if you wanted to move queries from one system to another, or simply back them up.

     
    
    #Backup Collection Data from source computer
    
    Get-CMDeviceCollection | Export-Clixml 'c:\OldComputer\AllCollections.xml'
    
    #Restore to target computer (This sets the limiting collection to "All Systems" and also assumes there is only one membership rule)
    
    $allCollections = Import-Clixml 'c:\NewComputer\AllCollections.xml'
    
    $allCollections | ? {$_.isbuiltin -eq $false} | % {
    
        New-CMDeviceCollection -LimitingCollectionId SMS00001 -Name $_.Name
    
        Add-CMDeviceCollectionQueryMembershipRule -CollectionName $_.Name -RuleName $_.CollectionRules.RuleName -QueryExpression $_.CollectionRules.QueryExpression
    
        }




    Mike Crowley | MVP
    My Blog -- Planet Technologies

    Wednesday, June 25, 2014 4:35 AM
  • I had to fix the solution of the friend below a little and got almost what I want. Not full info coming out.

    [WMI] '\\.\root\sms\site_EU1:SMS_Collection.CollectionID="EU100133"' | Format-table -Property CollectionRules

    The result is as follows and ends with ...} thus not showing the whole ino!

    CollectionRules                                                                                                              
    ---------------                                                                                                              
    {EU-Workstations-PL0, EU-Workstations-DE0, EU-Workstations-DE1, EU-Workstations-PL1...} 

    Any other suggestion on how to get the full list in Collection Rules?

    Friday, June 26, 2015 10:09 AM