Add AD/domain groups to local windows groups

If you need to add a list of AD/domain groups to a local windows group use the follwing script

For example to add the groups below to the local “Administrators” group use this syntax

  1. $group = “domain\groupname”, “domain\groupname2”, “domain\group name 3”
  2. net localgroup Administrators /add $group

 

If you want to publish this membership to remote computers, try this:

invoke-command -computername computer1,computer2,computer3 -scriptblock {$group = “domain\groupname”, “domain\groupname2”, “domain\group name 3”}

invoke-command -computername computer1,computer2,computer3 -scriptblock {net localgroup Administrators /add $group}

Advertisements