Simple Powershell command/script to add computers to SCCM 2012/2007 collections, we use to have many collections in our SCCM platform to control the patching, how we want to push the patches like daily collection or hourly collections with different maintenance windows configured, its easy to add servers manually if we want to add a single server, lets say we want to add hundreds of servers on a collections, how to do this with a simple Powershell command?
Also Read: PowerShell command to extract Group policy result for a list of Servers
Adding Multiple Computers to a Single SCCM Collection from a text file:
Open Powershell from SCCM Console to avoid importing SCCM module, if you want to work with PowerShell for SCCM, you should have opened SCCM Console, and the easiest way is to get into PowerShell with access to the SCCM module is to click the blue drop down arrow from the top of the SCCM console and click Connect via Windows PowerShell
Also Read: Enable Powershell Remoting on Windows server 2008 R2 and 2012
Create TXT file called server_list.txt (c:\temp\server_list.txt) and update the server details
Run below Powershell Command
Get-Content "c:\temp\server_list.txt" | foreach { Add-CMDeviceCollectionDirectMembershipRule -CollectionName "Windowsdailyrun" -ResourceID (Get-CMDevice -Name $_).ResourceID }
Note: You needs to change SCCM collection name and input file name as per your requirement
Collection name = Windowsdailyrun
Server list = c:\temp\server_list.txt
Also Read: Interesting oneline script written using windows command