Powershell: Add Active Directory computers to a group in bulk. | Zak Emerick's IT Blog

My IT blog for random ideas and solutions.

Powershell: Add Active Directory computers to a group in bulk.

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.

598 Total Views 1 Views Today


Post a Comment

Your email address will not be published. Required fields are marked *

 characters available