How To Bulk Remove Devices From SCCM Device Collection via Powershell

Jason Barrett Jason Barrett | | ConfigMgr

Today I needed to bulk remove multiple devices from multiple SCCM device collections.

Rather than do this manually I found a way to do this easily via powershell.

bulk remove devices from SCCM device collection

The command I am going to show you below will remove any devices with a direct membership in the device collection.

How To Bulk Remove Devices From SCCM Device Collection via Powershell

To bulk remove devices from a sccm device collection do the following steps

  1. RDP to your SCCM site server
  2. Open up the configuration manager console
  3. Open powershell via the console by clicking on the menu in the tool bar then click “Connect via powershell”
    sccm console powershell
  4. In the powershell window type Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass  then hit y and press enter
    set-execution policy
  5. Now lets get the information of the device collection we want to remove devices from. In the configuration manager console go to \Assets and Compliance\Overview\Device Collections\ and find the collection you want to use.
  6. For this guide I am going to use the “Test Collection” Device collection
    test sccm device collection
  7. With the script we can use either the collection name “Which is Test Collection” or we can use the collection id
  8. To get the Collection id right click on the device collection and select properties. The collection id will be shown at the bottom of the window, Below my collection ID is NCS000B6
    collection id
  9. Go back to the powershell window, and run the command you require
  10. Command 1 : Remove individual machines from the device collection (Replace %DEVICENAME% with your device you want to remove)
    By Collection name :  Remove-CMDeviceCollectionDirectMembershipRule -CollectionName “Test Collection” -ResourceName %DEVICENAME% -Force
    By Collection id  : Remove-CMDeviceCollectionDirectMembershipRule -CollectionID NCS000B6 -ResourceName %DEVICENAME% -Force
  11. Command 2 : Remove device name pattern
    By Collection name :  Remove-CMDeviceCollectionDirectMembershipRule -CollectionName “Test Collection” -ResourceName Device* -Force
    By Collection id  : Remove-CMDeviceCollectionDirectMembershipRule -CollectionID NCS000B6 -ResourceName Device* -Force
  12. Command 3 : Remove all devices
    By Collection name :  Remove-CMDeviceCollectionDirectMembershipRule -CollectionName “Test Collection” -ResourceName * -Force
    By Collection id  : Remove-CMDeviceCollectionDirectMembershipRule -CollectionID NCS000B6 -ResourceName * -Force
  13. Now check the device collection and the required members should now be removed

If you want to learn more about this command you can see more information by Clicking Here