Nov 28, 2013 Mike Terrill

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 collection

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.