Querying SCCM for Collection rules by Powershell
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?
January 21st, 2009 10:03pm

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

Free Windows Admin Tool Kit Click here and download it now
October 25th, 2010 3:44pm

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

October 25th, 2010 3:44pm

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

Free Windows Admin Tool Kit Click here and download it now
October 25th, 2010 3:44pm

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

July 17th, 2013 6:51pm

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

Free Windows Admin Tool Kit Click here and download it now
June 23rd, 2014 3:19pm

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

    }


June 25th, 2014 4:35am

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?

Free Windows Admin Tool Kit Click here and download it now
June 26th, 2015 6:12am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics