Find nearest domain controller?

Discussion in 'Scripting' started by Philip Colmer, Aug 15, 2008.

  1. I've got a multi-domain, multi-site infrastructure. I need to be able to
    query the list of domain controllers for a given domain and figure out which
    one is the nearest to me.

    If it helps, it would be safe to assume that the code is being run on a PC
    in a site that has a domain controller for the domain in question.

    Can someone suggest how this can be done?

    Thanks.

    --Philip
     
    Philip Colmer, Aug 15, 2008
    #1
    1. Advertisements

  2. Hi Philip,
    if the Domain controller is in the same site as the PC, it is usually the
    one, which is used as logonserver.
    So with
    echo %logonserver%
    you should get the domain controller, which responded most quick to the
    logon attempt.
    Best greetings from Germany
    Olaf
     
    Olaf Engelke [MVP], Aug 15, 2008
    #2
    1. Advertisements

  3. Thank you for the suggestion, Olaf, but I'm not looking for the domain
    controller that I've logged on against. I need to find the nearest domain
    controller for a specific domain - we have a multi-domain infrastructure that
    spans multiple sites and we've got administrators in multiple sites working
    on all of those domains, so my script needs to be able to connect to the
    nearest DC for a specific domain in order to reduce replication impact on the
    performance of the script.

    Regards

    Philip
     
    Philip Colmer, Aug 16, 2008
    #3
  4. Hi Philip.
    so you are sitting in one domain and neet to find the for you "nearest"
    domain controller for another domain from the PC you are just sitting on?
    Or do you mean the local site admin needs to find his local domain
    controller?
    In last case I still would tend to the logon server as criteria.
    Btw. - the best way to reduce network impact of scripts is in my eyes still
    to execute them directly on an appropriate server via Remotedesktop.
    The Remotedesktops mmc console is a great tool for that centralized access
    and you do not need to run security sensitive stuff directly from your
    desktop, giving any virus the same permission to access network ressources
    as yourself.
    Best greetings from Germany
    Olaf
     
    Olaf Engelke [MVP], Aug 16, 2008
    #4
  5. The problem I have is that I've been working on a script to create new user
    accounts and it needs to be able to create accounts in multiple domains
    during a single run session, mainly to be bullet-proof against administrators
    who don't split their CSV files up into separate domains and run the script
    on the best server as you suggest.

    It seems as if this is probably a harder problem to code for than I
    anticipated.

    --Philip
     
    Philip Colmer, Aug 17, 2008
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.