Last active
January 12, 2017 21:07
-
-
Save paulczy/fea716839bfc0b954d7eb7f85ab5e7c9 to your computer and use it in GitHub Desktop.
Get the first OU in distinguished name string.
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
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