Skip to content

Instantly share code, notes, and snippets.

@paulczy
Last active January 12, 2017 19:31
Show Gist options
  • Save paulczy/4584c708bbf171e077df5ee2194c07a5 to your computer and use it in GitHub Desktop.
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/
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