Powershell – SCCM 2012 – Add machine to Device Collection with a Direct Rule

Adding machines to device collections using the GUI can take quite a lot of time to achieve. Performing the task via Powershell takes a fraction of the time and can be expanded upon so that you can add multiple machines from various sources (text file, AD group etc).


  1. Test the collection using Get-CMCollection -Name $CollectionName

Code description

  1. Specify your device collection’s name in $CollectionName
  2. Specify your device name in $DeviceName
  3. The Add-CMDeviceCollectionDirectMembershipRule commandlet will then add the device to the device collection


$CollectionName = "Test1"
$DeviceName = "Computer1"

Add-CMDeviceCollectionDirectMembershipRule -CollectionName "$CollectionName" -ResourceID $(get-cmdevice -name "$DeviceName").ResourceID

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s