Remove bulk users from a Group(multi domain environment)

I want remove bulk users from an AD group, and the below command is working me, if group and users are in same domain, since our AD environment has one forest with three child domains, this command fails if the group or users were in different domain, I tried using $DC from group Domain/Domain Controller, User Domain/Domain Controller and global catalog, but it fails. could anyone help on this. Thanks in advance.

Remove-ADGroupMember -Identity $GroupName -Server $DC -Members $user -Confirm:$false

What’s the error that you are getting? Why does it fail?

I received below error in the provided scenarios:

when using global catalog as $DC
ERROR: remove-ADGroupMember : The server is unwilling to process the request

when using the Group domain as $DC
ERROR: remove-ADGroupMember : Cannot find an object with identity: ‘UserName’ under: ‘Group domain’.

when using the user domain as $DC
ERROR: remove-ADGroupMember : Cannot find an object with identity: ‘GroupName’ under: ‘User Domain’.

What happens if you try to save the objects from their corresponding Domains to variables first, before trying to remove users from a group?

For example:

$User = Get-ADUser -Server user.domain
$Group = Get-ADGroup -Server group.domain
Remove-ADGroupMember -Identity $Group -Members $User

Great… It works…

Thanks a lot

No worries! Glad to be of help.