How to get Domain Controllers Information in .NET

Waqas Anwar
29 August 2012

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);