Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch to another domain and get-aduser

I am on a server under the DomainA. I can use Get-ADUser and it's working fine.

Now there is a trust built between DomainA and DomainB. I would like to switch to DomainB and get all the users that's in OU=New Users, DC=DomainB, DC=com.

I tried these but I get an error.

$FetchDomainB = Get-ADUser -SearchBase "OU=New Users, DC=DomainB, DC=com" 

This asks me for Filter and i put in emailadress then it throws an error saying "Supplied distinguished name below to dc=DomainA,dc=net"

Same error is thrown for following code as well.

PS C:\> $test = Get-ADUser -SearchBase "dc=DomainB,dc=com" -filter {EmailAddress -like "*Smith_Karla*"} -Properties EmailAddress 
like image 810
Axiom Avatar asked Dec 17 '14 19:12

Axiom


People also ask

How do I transfer Domain from one Domain to another?

First, you need to export a list of users to a CSV file. This can be done with PowerShell or the User Export Tool. With the export tool, you can select to export from the entire domain, an OU or group. You can also change the columns to preserve user settings when moving to the new domain.

How do I connect to a different Domain in PowerShell?

In the above PowerShell script, Get domain name list using Get-AdForest cmdlet in active directory. Using ForEach, iterate over $Domain to get Hostname of each domain controller using Get-AdDomainController cmdlet in active directory. Using ForEach, iterate over $DCList to get aduser in domain using Get-AdUser cmdlet.


2 Answers

Try specifying a DC in DomainB using the -Server property. Ex:

Get-ADUser -Server "dc01.DomainB.local" -Filter {EmailAddress -like "*Smith_Karla*"} -Properties EmailAddress 
like image 112
Frode F. Avatar answered Oct 07 '22 08:10

Frode F.


I just want to add that if you don't inheritently know the name of a domain controller, you can get the closest one, pass it's hostname to the -Server argument.

$dc = Get-ADDomainController -DomainName example.com -Discover -NextClosestSite  Get-ADUser -Server $dc.HostName[0] `     -Filter { EmailAddress -Like "*Smith_Karla*" } `     -Properties EmailAddress 
like image 38
Drew Chapin Avatar answered Oct 07 '22 08:10

Drew Chapin