How to get Domain Controllers Information in .NET

if you want to read domain controllers information in .NET application you can use following code snippet.

First of all import System.DirectoryServices.ActiveDirectory namespace

using System.DirectoryServices.ActiveDirectory;

Then iterate the domain controllers using the DomainControllers property as shown below:

var domain = Domain.GetComputerDomain();
foreach (DomainController controller in domain.DomainControllers)
    Console.WriteLine("{0} {1}", controller.IPAddress, controller.Name);



About author

User avatar

Waqas Anwar

Founder of, Senior Consultant, Microsoft .NET and Web Technologies