• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 509
  • 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.

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

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