Adding Devices To A Collection Using PowerShell

Background

I get requested far too often to add devices to collections. Sometimes it’s 1 machine and sometimes it’s a 100 machines. I got tired of opening the SCCM/ConfigMgr console every time I received these requests.

So I thought, why not create a PowerShell script which does this for me without having to open the SCCM/ConfigMgr Console.

How to run the script

There are 4 parameters available for this script…

  • MultiAdd
    • Required: No
    • Inputs: Yes/No
    • Usage: Use this when adding multiple devices. Device names must be saved in a text file.
  • CollectionName
    • Required: No
    • Inputs: Collection Name
    • Usage: Use this when specifying the Collection Name. If parameter is not specific, you will be prompted with a list of collections from your environment to pick.
  • Computer
    • Required: No
    • Inputs: Computer Name
    • Usage: Use this when sepcifying a single device to add. If paramater is not specific, you will be prompted to enter Computer Name.
  • FilePath
    • Required: No
    • Inputs: Path to txt file
    • Usage: Specify the file path of the text file with device names. If not specified, you will be prompoted to browse and select the text file.

Examples

  1. Add computers from text file to a collection.
    Add-DeviceToCollection -FilePath C:\temp\sample.txt -CollectionName 'Amar - test'
  2. Add computer PC01 to a collection (prompt to select collection)
    Add-DeviceToCollection -Computer PC01

The Script

  Download

 

5 comments on “Adding Devices To A Collection Using PowerShell

    1. AvatarAmar Rathore Post author

      Hi Guy,

      To be honest I haven’t tried that. You would have to enable PowerShell support for the WIM before running the script.

      Press F8 to bring up the command prompt. Sorry replying from my phone. Lmk if you have any more questions. Feel free to message me on Twitter as well.

      Reply
      1. AvatarAmar Rathore Post author

        Actually i doubt it would work in WinPe since I’m pointing to a module which is loaded after the console is installed.

        Reply
  1. AvatarAmar Rathore Post author

    Actually i doubt it would work in WinPe since I’m pointing to a module which is loaded after the console is installed.

    Reply

Leave a Reply

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