Adding Multiple Devices To SCCM Collection PowerShell
Maybe your like
I recently needed to add a few hundred devices to a collection in SCCM. I couldn’t use a query to achieve this as there where no attributes that I could use. So it would have to be a direct query and I didn’t really want to manually add hundreds of servers as this would take a long time and PowerShell is a much easier and faster option. I decided to write a quick script to get a list of device from a txt file and do a loop to add each device to the specified collection.
First I need to open a PowerShell connect to SCCM I prefer to use Powershell ISE as I can edit and test my script while in one console. To connect go to the SCCM console On the blue drop down icon on the top left, click it and then choose Connect via Windows PowerShell ISE.

Once PowerShell ISE is open you should see the connection script. Just click run script at top of ISE to connect to SCCM. 
Once in ISE copy the script below and change the collectioname, computers and logpath variables to the correct location and collection that you want to added to. Below is what the script should look like when it run.

$collectionname = “RDS Deploy Collection” $Computers = Get-content “c:\temp\Server_List.txt” $logpath = “c:\temp” foreach($computer in $computers) { try { Write-Host “Adding $computer to $collectionname” -ForegroundColor Green Add-CMDeviceCollectionDirectMembershipRule -CollectionName $collectionname -ResourceId (get-cmdevice -Name $computer).ResourceID } catch { Write-Warning “Cannot add client $computer object may not exist” $computer | Out-File “$logpath\$collectionname-invalid.log” -Append $Error[0].Exception | Out-File “$logpath\$collectionname-invalid.log” -Append } }
There is also a log file that will be export to give devices that have not been added and the error exception generated by PowerShell.

Share this:
- X
Related
Tag » Add Computer To Sccm Powershell
-
Import-CMComputerInformation (ConfigurationManager)
-
Add-CMDeviceCollectionDirectMembershipRule - Microsoft Docs
-
Add Multiple Devices To SCCM Collection Using PowerShell
-
Add Multiple Computers To SCCM Collection Using Powershell
-
Import Bare Metal Devices Into SCCM Using PowerShell
-
Add Computers From A File To A SCCM Collection Using PowerShell ...
-
Powershell Script To Add Computer To SCCM Collection
-
Add Computer To A SCCM Device Collection. : R/PowerShell - Reddit
-
PowerShell Add Computers To Collection From CSV - SCCM ConfigMgr
-
UMN-m1 1.0.3 - PowerShell Gallery
-
UMN-m1 1.0.4 - PowerShell Gallery
-
Getting Started With SCCM Powershell Cmdlet - System Center Dudes
-
Use PowerShell To Add Computers To AD Security Groups During ...
-
Add Computer To SCCM Collection - Script Center - Spiceworks