snagrat Posted May 9, 2024 Posted May 9, 2024 (edited) I want to get all members from a group in DomainA, and add them to a group in DomainB. I can do the process manually and it works, so the trust is all good. The follow returns an error: Get-ADGroupMember -Identity "GroupA" -server 'DomainA' | ForEach-Object {Add-ADGroupMember -Server 'DomainB' -Identity "GroupB" -Members $_.distinguishedName} The error is "Add-ADGroupMember : Cannot find an object with identity: 'xxxx' under: 'DC=DomainB,DC=local' I haven't got far on the web apart from this script that works but requires the username is inputted - which I do not know until I get them from the GroupA $DomainA = 'DomainA.local' $DomainB = 'DomainB.local' $UserName = 'joe.bloggs' $GroupName = 'GroupB' $User = Get-ADUser -Identity $UserName -Server $DomainA $Group = Get-ADGroup -Identity $GroupName -Server $DomainB Add-ADGroupMember -Identity $Group -Members $User Can any suggest something I can try? Edited May 9, 2024 by snagrat
snagrat Posted May 9, 2024 Author Posted May 9, 2024 I want to get all members from a group in DomainA, and add them to a group in DomainB. I can do the process manually and it works, so the trust is all good. The follow returns an error: Get-ADGroupMember -Identity "GroupA" -server 'DomainA' | ForEach-Object {Add-ADGroupMember -Server 'DomainB' -Identity "GroupB" -Members $_.distinguishedName} The error is "Add-ADGroupMember : Cannot find an object with identity: 'xxxx' under: 'DC=DomainB,DC=local' I haven't got far on the web apart from this script that works but requires the username is inputted - which I do not know until I get them from the GroupA $DomainA = 'DomainA.local' $DomainB = 'DomainB.local' $UserName = 'joe.bloggs' $GroupName = 'GroupB' $User = Get-ADUser -Identity $UserName -Server $DomainA $Group = Get-ADGroup -Identity $GroupName -Server $DomainB Add-ADGroupMember -Identity $Group -Members $User Can any suggest something I can try? OK figured it out. Seems this works from the original try: Get-ADGroupMember -Identity "GroupA" -server 'DomainA' | ForEach-Object {Add-ADGroupMember -Server 'DomainB' -Identity "GroupB" -Members $_} Not sure what it means when it ends -Members $_ assume it means it will use the default returned attribute? 1
mavhc Posted May 10, 2024 Posted May 10, 2024 It should send the entire object not just one property of the object
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now