• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 511
  • Last Modified:

Powershell get-user will oly search connected dc


We have a rootdomain epsilongroup.net and 10 subdomains, eab.epsilongroup.net, eus.epsilongroup.net etc.

When i run a get-user the cmd will only search the connected active directory for the rootdomain that the domaincontroller its in. In this case epsilongroup.net. (im connected to the rootdomaincontroller).
However, i want to search ALL subdomains from one source. I know i can add -domaincontroller xxxx.eab.epsilongroup.net and search that domain, but this requires me to add all domaincontrollers one after another. Is there a way to recursevly search the domain?
  • 2
1 Solution
You can always try using Get-ChildItem with -Recurse switch and filter out only users. But that kind of query will impact the server heavily.
Or you can issue Foreach ($dc in $controllers) loop where you'd define DCs' list in the $controllers variable.
OR... use ADSI query to list domain controllers:
and then use Get-ADUser in the Foreach loop.
dontmindmeAuthor Commented:
Could you please enter a syntax i could try?
For example: I want to "get-user eabsgn"
OK, try something like this:
Import-Module ActiveDirectory
$root=[ADSI]"LDAP://OU=Domain Controllers, dc=yourdomain, dc=local"
$dc_list = $root.PSBase.Children | ForEach-Object { $_.Name }
foreach ($dc in $dc_list)
    Get-ADUser user -Server $dc

Open in new window

Well it uses hardcoded value. Just let me know if you'd like to make it more... interactive.
Of course it'll cycle through all the domain controllers, no matter if it belongs to the same domain or not.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improved Protection from Phishing Attacks

WatchGuard DNSWatch reduces malware infections by detecting and blocking malicious DNS requests, improving your ability to protect employees from phishing attacks. Learn more about our newest service included in Total Security Suite today!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now