Need help on Powershell Script

Is there a way we can access different domain via powershell to retrieve information?
Ex : domain A and B has the same security group but when I run my script if retrieves information only from domain A or Domain B based on the pc’s domain membership.
Any help on this would be great!

If you’re using the ActiveDirectory module, just specify the name of the target domain in the -Server parameter, ie:

Get-ADGroup -Server otherdomain.local -Filter *

You will need to supply credentials to the other domain as well unless they are in a single forest and you are a member of the Enterprise Admins group