Fill SCCM collection with PowerShell

Hi everyone,

In this post, I’m going to show you how to fill an SCCM collection with PowerShell from a file that contains device names. This can be useful if you want to deploy software or settings to a specific group of devices that you have already identified.

SCCM collections are logical groups of resources that you can use for management tasks. You can create collections for devices or users, and specify membership rules based on queries, direct membership, or include/exclude other collections.

To create a device collection with PowerShell, you can use the New-CMDeviceCollection cmdlet from the ConfigurationManager module. You need to provide a name for the collection and a limiting collection name that defines the scope of potential members.

For example, this command creates a collection named “DeviceCollection_DummySoftware” that can include any device from the “All Systems” collection.

To fill the collection with devices from a file, you can use the Get-Content cmdlet to read each line of the file as a device name. Then, you can use the Add-CMDeviceCollectionDirectMembershipRule cmdlet to add each device as a direct member of the collection. You need to provide the collection name and the resource ID of the device, which you can get with the Get-CMDevice cmdlet.

For example, this command reads device names from “C:\pathtofile\clients.txt” and adds them as direct members of “DeviceCollection_DummySoftware”:


Get-Content "C:\pathtofile\clients.txt" | foreach { $_; Add-CMDeviceCollectionDirectMembershipRule -CollectionName "DeviceCollection_DummySoftware" -ResourceID (Get-CMDevice -Name $_).ResourceID }

That’s it! You have successfully filled an SCCM collection with PowerShell from a file. You can now use this collection for any management tasks that you want.

I hope you found this post helpful and informative.

Thanks for reading!


Posted

in