PowerShell add Computers to Collection from CSV – SCCM ConfigMgr

This is a quick and dirty PowerShell script to import from CSV using the name of the machine to find the resource ID. It will only work for machines that are already a member of the Site you are working on.

For example you could use one of my other scripts to export from one collection and then add to a new collection.

As always this is provided as is, usage is in the header and please use the modded by field 😉

5 Replies to “PowerShell add Computers to Collection from CSV – SCCM ConfigMgr”

  1. Create a file “sccc.txt” contain the list of pcs/devices name
    Click on properties of device collection and copy the collection Id
    Open power shell from SCCM
    Run the command “Get-Content “C:\Users\altaf\Desktop\sccm.txt” | foreach { Add-CMDeviceCollectionDirectMembershipRule -CollectionId PKISB0015B -ResourceID (Get-CMDevice -Name $_).ResourceID }”
    Now check you collection
    for details check

    https://gallery.technet.microsoft.com/Multiple-Computers-to-a-fdc35ffa

  2. Get-CMDevice : The term ‘Get-CMDevice’ is not recognized as the name of a cmdlet, function, script file, or operable
    program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:142
    + … llectionName “Malwarebyte_Group_12” -ResourceID (Get-CMDevice -Name $ …
    + ~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Get-CMDevice:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Leave a Reply

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

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.