How to fill an SCCM (ConfigMgr) device collection from a text file with device names – handy when you want to deploy software or settings to a group of devices you have already identified.

Collections are logical groups of resources. Membership can come from queries, direct membership rules or include/exclude rules. The commands below use the ConfigurationManager module.

Create the collection

New-CMDeviceCollection needs a name and a limiting collection that defines who can be a member at all:

New-CMDeviceCollection -Name "DeviceCollection_DummySoftware" -LimitingCollectionName "All Systems"

Add devices from a file

Read one device name per line with Get-Content, look up the resource ID with Get-CMDevice and add it with Add-CMDeviceCollectionDirectMembershipRule:

Get-Content "C:\path\to\clients.txt" | ForEach-Object {
    $_
    Add-CMDeviceCollectionDirectMembershipRule -CollectionName "DeviceCollection_DummySoftware" `
        -ResourceId (Get-CMDevice -Name $_).ResourceID
}

That’s it – the collection is ready for deployments.

Originally published on anyresearch.net. These are notes from real-world admin work – test before you use them in production.