How to add or remove Entire Directory users from any group in Active Directory

How to add or remove Entire Directory users from any group in Active Directory powershell.
I am creating script to Add or remove user in AD groups.
My script is working for same domain. but If user is exist in another domain or forest, i am not able to perform action onto that.
Please help me on this.

When working with group members from another domain, or when working with groups in another domain, you need to fetch the user object or group first. There is an MSDN article that explains why and has some example code:

Adding Removing Members from Another Forest or Domain

try this:

Add-ADGroupMember -Identity ‘somegroup_in_domain_1’ -Members (get-aduser -Filter * -Server “domain_controller_2”)