I had a need to add a lot of computers that were spread throughout my Active Directory structure to a computer group. I didn’t want to manually go though AD and right click computers to add them to this group. So I came up with a very simple script to do just that. You can see it below.
$comps= Get-ADComputer -LDAPFilter "(name=computername*)" -SearchBase "DC=domain,DC=local"
foreach ($comp in $comps)
Add-ADGroupMember "ComputerGroup" $comp
This snippet will select computers based on the name= string and place them in group “ComputerGroup”. Use the fully DN for the search base.