Adding computer objects from OU to multiple security groups

I need to get computer objects from particular AD OU and import them into multiple (two) security groups. This of course works for a single security group, but not sure how to do multiple groups.

 

$Comps = Get-ADcomputer -SearchBase 'ou=test ,ou=all computers,dc=name1,dc=name2,dc=com' -filter *
add-adgroupmember -identity 'SecGroup' -members $Comps

Did you try to search for it? There are literally thousands of examples all over the internet and probrably even hundreds here in this forum. Take a look at the cmdlet Add-ADPrincipalGroupMembership and read the complete help including the examples, please.

I have searched. Everything I find is for adding the systems in an OU to one group not multiple groups. I am willing to accept that I can’t find the answer at this point and this is the reason I posted the question here. Either way I will keep looking. Thank you for your reply.

Did you read the help in the link I posted?

Yes I got it now. Took me a minute. I think I was confused on the difference between add-adprincipalgroupmembership vs add-adgroupmember. Thank you again for your help.

I’m glad it helped. :wink: If you need more help - come back.