Last active
January 12, 2017 19:31
-
-
Save paulczy/4584c708bbf171e077df5ee2194c07a5 to your computer and use it in GitHub Desktop.
Convert Distinguished Name to Canonical Name. A C# port of a PowerShell script by Glenn Sizemore. http://practical-admin.com/blog/convert-dn-to-canoincal-and-back/
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
static string ConvertFromCanonical(string cn) | |
{ | |
var canoincal = "host.tempworks.com"; | |
var obj = canoincal.Replace(",", @"\,").Split('/'); | |
var dn = "CN=" + obj[obj.Count() - 1]; | |
for (int i = obj.Count() - 2; i >= 1; i--) | |
{ | |
dn += ",OU=" + obj[i]; | |
} | |
foreach (var item in obj[0].Split('.')) | |
{ | |
dn += ",DC=" + item; | |
} | |
return dn; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment