Using the new ConfigMgr 2012 PowerShell cmdlets, there are three different ways to add computers to a device collection. Just like in the console, you can add computers via a direct membership rule (Add-CMDeviceCollectionMembershipRule), a query membership rule (Add-CMDeviceCollectionQueryMembershipRule) and also an include collection membership rule (Add-CMDeviceCollectionIncludeMembershipRule). In order to use these cmdlets, the collection already needs to be created. In my previous post on my own blog, How to quickly create Collections using New-CMDeviceCollection, I demonstrated one way of creating device collections based off of a for loop and using each loop as an index number in the collection name.

In this post, since we will be reading a list of computers from a text file, we will use the direct membership rule cmdlet Add-CMDeviceCollectionMembershipRule to add them to the device collection. Using this cmdlet, you can add a device resource object to one or more device collections. Since collection names are unique in CM 12, it is easiest to reference the collection that you want to add objects to using the -CollectionName parameter.  For the device that we are trying to add, the easiest way is to get the resource ID and use the -ResourceId parameter. We can get the resource ID of a device called PC01 using the Get-CMDevice cmdlet.

Your use of these example scripts or cmdlets is at your sole risk. This information is provided “as-is”, without any warranty, whether express or implied, of accuracy, completeness, fitness for a particular purpose, title or non-infringement. I shall not be liable for any damages you may sustain by using these examples, whether direct, indirect, special, incidental or consequential. That said, enjoy!

Continue reading at Mike’s personal blog.

Mike Terrill
Mike’s career has been focused around systems management (ConfigMgr) and operating system deployment for almost 20 years (ever since SMS v1.2). He founded and runs the Arizona Systems Management User Group ( He specializes in the design, architecture and installation of System Center Configuration Manager and also Windows operating system deployments. Mike has designed, architected and deployed System Center Configuration Manager in several Fortune 100 companies and has worked with some of the world's largest organizations (400K+ seats). Mike is now a Technology Architect at 1E. In this role, he provides technical direction for 1E technologies as they relate to Configuration Manager and operating system deployment. You can find him on twitter (@miketerrill) and read his personal blog at