How to add computers listed in a text file to a device collection


How to add computers listed in a text file to a device collectionUsing 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 | Systems Management Practice Lead

To explore this issue further, or discuss other industry challenges, contact us at, or join our LinkedIn forum, 1E INSIDEV1EW.

If you found this article helpful, please take a moment to share it with your contacts using the social media buttons to the left.

about Mike Terrill

Mike Terrill is the Product Manager for Windows Migrations and User-centric Application Management at 1E. He is focused on Windows Systems Management and Operating System Deployment using Microsoft and 1E technologies. Mike's specializes in System Center 2012 Configuration Manager and he has been using this product since Systems Management Server (SMS) 1.2. He has designed, architected, implemented, and worked with some of the leading top Fortune companies. In his previous role at 1E as the Systems Management Practice Lead, Mike's last project in 1E Professional Services included deploying System Center 2012 Configuration Manager and Windows 7 to a 450K seat environment.  Mike is also the founder and user group leader for the Arizona Systems Management User Group (, and blogs at

Would you like to share your thoughts?

Your email address will not be published.

Please type the characters of this captcha image in the input box