Skip to content

Instantly share code, notes, and snippets.

@billtaichi
Last active December 19, 2015 11:59
Show Gist options
  • Save billtaichi/5951508 to your computer and use it in GitHub Desktop.
Save billtaichi/5951508 to your computer and use it in GitHub Desktop.
Snippet to obtain Active Directory Path
public string ActiveDirectoryPath()
{
DirectoryEntry root = new DirectoryEntry("LDAP://RootDSE");
using (root)
{
string dnc = root.Properties["defaultNamingContext"][0].ToString();
string server = root.Properties["dnsHostName"][0].ToString();
string adsPath = String.Format("LDAP://{0}/{1}", server, dnc);
return adsPath;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment