Created
February 25, 2014 16:32
-
-
Save mkchandler/9212462 to your computer and use it in GitHub Desktop.
Gets a list of all available domain controllers or find a single available controller.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.DirectoryServices.ActiveDirectory; | |
namespace ActiveDomainControllers | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
// Get a list of all available domain contollers | |
var domainControllers = DomainController.FindAll(new DirectoryContext(DirectoryContextType.Domain, "domain.name")); | |
foreach (DomainController domainController in domainControllers) | |
{ | |
Console.WriteLine(domainController.Name); | |
} | |
// Finds a single domain controller that is currently available | |
var singleDomainController = DomainController.FindOne(new DirectoryContext(DirectoryContextType.Domain, "domain.name"), LocatorOptions.ForceRediscovery); | |
Console.WriteLine("Single: " + singleDomainController.Name); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment