简体   繁体   中英

Copying AD group members to another AD group

I need to copy all members from one AD group to another. The code I am using is failing.

Caveat: The members in the source group are from different (trusted) domains. I am not a Powershell expert.

Example code:

$Source_Group = Get-ADGroupMember -Identity "CN=Team1_ReadOnly, 
OU=Team1,OU=TEAM_GROUPS,OU=Groups,OU=Business,DC=Server1,DC=Contoso,DC=com" 
-Server "Server1@contoso.com"
Add-ADGroupMember -Identity " CN=Team2_ReadOnly, 
OU=Team2,OU=TEAM_GROUPS,OU=Groups,OU=Business,DC=Server1,DC=Contoso,DC=com " 
-server "Server1@contoso.com" -Members $Source_Group  

Error Output:

错误输出

Has anyone come across this issue before with users from different domains?

We have moved all users who are in the same domain as the destination group without issue in the past.

To answer my own question.

The code was fine. It turns out the person (DBA) running the script was running it directly from the target domain controller. The target domain controller did NOT have a trust with a particular domain that one of the members was attributed to. I tested from my local machine that had rights across all domains.

When the script was run on a machine that had a trust with all domains it worked fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM