Powershell get-user will oly search connected dc

Posted on 2011-10-10
Last Modified: 2012-12-05

We have a rootdomain and 10 subdomains,, 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 (im connected to the rootdomaincontroller).
However, i want to search ALL subdomains from one source. I know i can add -domaincontroller and search that domain, but this requires me to add all domaincontrollers one after another. Is there a way to recursevly search the domain?
Question by:dontmindme
    LVL 11

    Expert Comment

    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.

    Author Comment

    Could you please enter a syntax i could try?
    For example: I want to "get-user eabsgn"
    LVL 11

    Accepted Solution

    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

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    A commonly asked question on the site recently has been regarding how do I share the GAL between different forests? I want a list of Contacts representing all the users in a remote domain, How do i get them? It's a problem I was posed with a litt…
    This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
    Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
    The viewer will learn how to dynamically set the form action using jQuery.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now