List of Windows DCs

Original posts: https://stackoverflow.com/questions/354037/how-do-i-find-out-which-computer-is-the-domain-controller-in-windows-programmati

Your own logon server:

echo %LOGONSERVER%

Own logon server with C#:

using System.DirectoryServices.AccountManagement;
// (also need to add the assembly System.DirectoryServices.AccountManagement)

using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
{
    string controller = context.ConnectedServer;
    Console.WriteLine( "Domain Controller:" + controller );
}

List of all domain controllers in particular domain:

nltest /dclist:{domainname}

List of all domain controllers computer is connected to:

nltest /dclist:

Leave a Reply