Add Multiple Devices to SCCM collection using PowerShell

Using PowerShell you can easily bulk add multiple devices to SCCM device collection. Using this guide, you will be able to import multiple devices into a target device collection using ConfigMgr PowerShell module.

There could be situations when you have to add a few hundred devices to a collection in SCCM. If it was a single device, you would use a directly query. However when you have got lot of computers, adding each of them would take a long time.

Thanks to PowerShell because it is a much easier and faster option to bulk add devices to SCCM device collection. We will accomplish our task using Add-CMDeviceCollectionDirectMembershipRule which adds a Direct Rule membership rule to a device collection. More info here.

Step 1 – Create a device collection in SCCM

  • Open the SCCM Console. Go to Assets and Compliance > Overview > Device Collections.
  • Click Create Device Collection in the top ribbon.
  • The Create Device Collection Wizard opens. Specify a name of the new device collection and select the limiting collection. Click Next.

create device collection in sccm

On the Membership Rules page, don’t add any rule. Click Next.

Define membership rules for the collection

When you create a device collection without adding any resources, you get a warning. This collection has no membership rules… Click OK since we will be importing multiple devices into this device collection later.

Add Multiple Devices to SCCM collection using PowerShell Snap3

On the Summary page, click Close.


On the Completion page, click Close.


Step 2 – Prepare the Computers List

After creating the target device collection, prepare a TXT file that contains all devices that you wish to add to device collection. In this example, the file name is List_computers.txt and contains the following devices.

Add Multiple Devices to SCCM collection using PowerShell

Step 3 โ€“ Import the Computers using ConfigMgr Powershell cmdlets

On the top ribbon of the ConfigMgr console, click to the blue arrow and click Connect via Windows PowerShell.

Add Multiple Devices to SCCM collection using PowerShell Snap7

Copy and paste the below command and donโ€™t forget to change the text file location and the target collection name. Execute the command.

Get-Content "E:\Sources\Import\List_computers.txt" | foreach { Add-CMDeviceCollectionDirectMembershipRule -CollectionName "Computer List" -ResourceID (Get-CMDevice -Name $_).ResourceID }

Add Multiple Devices to SCCM collection using PowerShellAfter few minutes (It depends of the computers number), the device collection import task should be complete. You will find all the devices added to the device collection in SCCM.

Youssef Saad

Hi, I am Youssef Saad from Morocco, I have approximately 6 years of IT infrastructure experience. My main focus is the Enterprise Device Management and increasing the End-user Digital Experience. Recently, I have been working on multiple technologies such as MEMCM / Configuration Manager, Intune and Nexthink. I am passionate about sharing my experience with other people and I participate in different blogs / forums.

Related Articles


  1. It worked for me after adding a parameter after for Get-CMDevice.
    Get-Content “xxx.txt” | foreach { Add-CMDeviceCollectionDirectMembershi
    pRule -CollectionName “xxx” -ResourceID (Get-CMDevice -Name $_ -Resource).ResourceID}

  2. Just use the free “Right Click Tools” software for SCCM/MECM, is so much faster, easier and effective for this action and several others ๐Ÿ˜‰

  3. nervermind
    i foud it =)
    just change a few params.

    Get-Content “E:\Sources\Import\List_users.txt” | foreach { Add-CMUserCollectionDirectMembershipRule -CollectionName “User List” -ResourceID (Get-CMUser -Name $_).ResourceID }

  4. Hi
    thanks for this script, real time saving .
    do you know a way to do the same with user collections?

    thank you

  5. New to sccm and packaging deployments. Following the step by step. Not sure how this would solution would work. I”m get the following error when running the cmd:

    Add-CMDeviceCollectionDirectMembershipRule : Cannot bind argument to parameter ‘ResourceId’ because it is null.
    At line:1 char:144
    + … ame “Sophos Machines” -ResourceID (Get-CMDevice -Name $_).ResourceID}
    +                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       + CategoryInfo         : InvalidData: (:) [Add-CMDeviceCol…tMembershipRule], ParameterBindingValidationExceptio
       + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.ConfigurationManagement.Cmdlets

    Seems to me if we are trying to populate my sccm Collection with my machines listed in the .txt file, how would Get-CMDevice know about the device to get a ResourceID?

  6. not working. TXT is referenced correctly. Error Output: something like this:

    Tunrs out the quotation marks in the article above do not like copy pasty nor the copy cmdlet of the html webpage.

    -ResourceID (Get-CMDevice -Name $_).ResourceID }
    ForEach-Object : Cannot bind parameter ‘RemainingScripts’. Cannot convert the “Get-Content” value of type
    “System.String” to type “System.Management.Automation.ScriptBlock”.
    At line:1 char:53
    + … Alle.txt” | foreach { Add-CMDeviceCollectionDirectMembershipRule -Col …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [ForEach-Object], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ForEachObjectCommand

    1. Correction: Working, after I replaced the Quotations Marks that came via the copy cmdlet of this webpage to my clipboard. No idea why they copied over wrong. Also, looking correct in powershell, but beeing the wrong characters. Thanks for this solution.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button