PowerShell 3+:
$computers = Get-ADComputers * | Select -ExpandProperty SamAccountName Get-ADGroup testgroup | Add-ADGroupMember -Member $computers
Add-ADGroupMember might actually be able to take ADComputer objects. I don’t remember off the top of my head and I don’t have a test environment at hand right now.
PowerShell 2:
$computers = @() # list of computer distinguishedName values
$group = [ADSI]"LDAP://CN=TestGroup,OU=Groups,DC=example,DC=com"
foreach($computerDn in $computers) {
# The .Add() method outputs the number of objects in the list, so Out-Null to avoid unnecessary clutter
$group.Properties["member"].Add($computerDn) | Out-Null
}
$group.CommitChanges()