For various reasons for example – Client OS deployment, Application Deployment match Organization OU structure with SCCM Device Collection or for any short team need for adding computer to Collection using Direct Membership method.
Below is the PowerShell command to read the computer names from text file and then add those computers to SCCM collection:
Text File – C:SCCMComputers.txt :
Computer01
Computer02
Computer03
Collection Name: “Abobe Photoshop”
$Computers = Get-Content C:SCCMComputers.txtforeach ($computer in $Computers) {Add-CMDeviceCollectionDirectMembershipRule -CollectionName "Adobe Photoshop" -ResourceID $(Get-CMDevice -Name $_.computer).ResourceID}