Q: Powershell - Adding users to groups in another domain Anyone know how to add a user to a group in another domain that is trusted?
Say I'm logged into a computer in domain apple and I want to add a user (in domain orange) to group sg-California in domain orange. How do I login with my other domain admin credentials to run the command: 
Add-ADGroupMember -Identity sg-California -Members userindomainorange


A: Ultimately I found that you needed to point powershell at a domain controller and have your credentials input into a var.
# User to add
$User = Read-Host "Enter user samid"

# Domain controller to run against
$TargetDomainController = "dc01.domain.loc"

# Get credentials
$AdminCredsTargetDomain = Get-Credential TargetDomain\user

# Run command
Add-ADGroupMember -Identity $TargetGroup -Members $User -Server $TargetDomainController -Credential $AdminCredsTargetDomain


A: You use the -Credential parameter to run the command with your admin credentials. As long as your AD trusts and everything is set up correctly, you shouldn't have a problem.
#Get your credentials
$AdminCredentials = Get-Credential "DomainOrange\AdminUser"

#Run AD command with credentials
Add-ADGroupMember -Identity sg-California -Members DomainOrange\userindomainorange -Credential $AdminCredentials


A: I was getting "Add-ADGroupMember : A referral was returned from the server"
when using this method. 
I had to resort to using Set-ADObject: Set-ADObject -Identity GroupDN -Add @{member=MemberDN} -Server DC
where: 


*

*GroupDN is the distinguished Name of the group

*MemberDN is the distinguished Name of the Member to add

*DC is the domain controller where the group is

