Powershell Script To Add Computer To SCCM Collection

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

Related posts:

Default ThumbnailCompare Installed Windows Security Patches with other Servers Default ThumbnailWhy PowerShell remoting can’t be enabled on a Windows server 2008 Default ThumbnailEnable Powershell Remoting on Windows server 2008 R2 and 2012 GPO Update failed with LDAP Bind function call failed error on Windows Server 2016/2019/2012 and Windows 10 Microsoft August 2020 Patch issues and unanswered questions: No Netlogon events in Domain Controller logs after August 2020 Patches

Tag » Add Computer To Sccm Powershell