Jump to content

Recommended Posts

Posted (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 by snagrat
Posted
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?

  • Thanks 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...