Bulk Add Devices to a Collection using Powershell

Bulk Add Devices to a Collection using Powershell

If you are in a situation where you need to add multiple devices to a collection using the direct membership rule then instead of manually going through the GUI and having to search for and select each device (which can be very time consuming if there are a lot of devices) you can use a simple Powershell script directly from the SCCM Console to achieve this.

Steps to Bulk Add Devices to a collection:

Firstly create a txt file and save it in a location of your choice (The powershell script will reference this location) containing a list of devices you wish to add to the collection.

Next from within the SCCM Admin console click the dark blue ribbon at the top and choose “Connect via Powershell”.


Once the powershell window has launched you are now connected directly to your SCCM site.

Run the following script: (Replace the location of the text file to match your own and also replace the “Collection Name” with the name of the collection you are adding resources to)

Get-Content “C:\Devices.txt” | foreach { Add-CMDeviceCollectionDirectMembershipRule -CollectionName “Collection Name” -ResourceID (Get-CMDevice -Name $_).ResourceID }

You can now do an update collection membership from within the SCCM console and you will notice the devices will have now been added.


Leave a Reply

Your email address will not be published.