powershell - Add users from another domain to AD group -
i need add users 1 ad group ad group. both groups in same domain, though users domain in forest.
domain "lpc": $source_group , $destination_group
 domain "forestx": users  
here 1 example wrote of this microsoft article:
$source_group = "cn=testsrc,ou=xxx,ou=yyy,dc=lpc,dc=de"  $destination_group = "cn=testdest,ou=xxx,ou=yyy,dc=lpc,dc=de"   $sourceuseres = get-adgroupmember -identity $source_group  foreach ($person in $sourceuseres) {      $user = get-aduser $person -server forestx-dc-1     add-adprincipalgroupmembership -server lpc-dc-1 $user -memberof $destination_group } get-aduser $person -server forestx-dc-1 seems contain right object if write comand line, reference seems not work in add-adprincipalgroupmembership statement.
i found answer myself using set-adobject command:
$source_server = "x1" $source_group = get-adgroup "xxx" -server $source_server $destination_server = "y1" $destination_group = get-adgroup "yyy" -server $destination_server  $sourceuseres = get-adgroupmember -identity $source_group   foreach ($person in $sourceuseres) {     set-adobject -identity $destination_group -add @{member=$person.distinguishedname} -server $destination_server } 
Comments
Post a Comment