Skip to content

Instantly share code, notes, and snippets.

@paulczy
Last active January 12, 2017 21:07
Show Gist options
  • Save paulczy/fea716839bfc0b954d7eb7f85ab5e7c9 to your computer and use it in GitHub Desktop.
Save paulczy/fea716839bfc0b954d7eb7f85ab5e7c9 to your computer and use it in GitHub Desktop.
Get the first OU in distinguished name string.
string GetFirstOU(string dn)
{
var firstOU = dn.Split(',')
.FirstOrDefault(x => x.StartsWith("ou=", StringComparison.OrdinalIgnoreCase));
if (string.IsNullOrEmpty(firstOU)) return null;
var result = Regex.Replace(firstOU, Regex.Escape("ou="), "".Replace("$", "$$"), RegexOptions.IgnoreCase);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment