Powershell: Add List Of Devices To Collection

Home/PowerShell, SCCM/Powershell: Add List Of Devices To Collection

Powershell: Add List Of Devices To Collection

This is a very simple PowerShell Script, that will make your daily Operations in SCCM so much easier! This PowerShell script will add a list of computer/devices into a collection.

Remember that there are many ways of doing it! But I think this is the easiest way to add bulk devices to a collection. If you find another easier way of doing it, please share your find in the comment field below.

So let’s get to it!

Below here you see 2 different PowerShell commands. Both commands will add a list of devices to a specific collection.
Both commands are very similar only difference is that the first PowerShell Command will add devices to the collection based on a Collection ID. The Second PowerShell command will add devices to the collection based on a collection Name.

Get-Content "C:\TEMP\CollectionMembers.txt" | foreach { Add-CMDeviceCollectionDirectMembershipRule -CollectionID "CollectionID" -ResourceID (Get-CMDevice -Name $_).ResourceID }

OR

Get-Content "C:\TEMP\CollectionMembers.txt" | foreach { Add-CMDeviceCollectionDirectMembershipRule -CollectionName "MyCollectionName" -ResourceID (Get-CMDevice -Name $_).ResourceID }

 

OBS: Replace the green lines in the PowerShell script with your own Collection name or Collection ID.  You can also change the Get-Content value to match your own path for the .txt file that cotains the list of the devices.

By | 2018-06-12T08:56:41+00:00 September 12th, 2017|Categories: PowerShell, SCCM|Tags: , , , , |0 Comments

About the Author:

Leave A Comment