Power ShellSCCMScripts
Add/Remove bulk Devices From Collection
Today i am going to show how to Add or Reemove bulk devices from the device Collection.
As a sccm engineer we usually see these scenarios to add and remove bulk devices from the collection depends on the project type.
Add Devices
- Create a text files and save it local machine like “import-list.txt”.
- Copy the Device Collection name from sccm
- open powershell from Sccm Console, and run the script first
- Then add the following powershell line and modify the text file name and device collection name according to your
#add devices to the Collections
Get-Content “C:\import-list.txt” | foreach { Add-CMDeviceCollectionDirectMembershipRule -CollectionName “Device collection name here..” -ResourceID (Get-CMDevice -Name $_).ResourceID }
Follow same above steps for Removing devices
#Remove devices from collection
Get-Content “C:\remove-list.txt” | foreach { Remove-CMDeviceCollectionDirectMembershipRule -CollectionName “Device collection name here..” -ResourceID (Get-CMDevice -Name $_).ResourceID }