获取您在 AD 对象选项卡中看到的 'Canonical name of object'

Obtaining 'Canonical name of object' that you see in the AD Object tab

正在尝试获取在 AD 用户帐户的“对象”选项卡中找到的'Canonical name of object'。

我可以得到 distinguishedName 和 cn 属性,但两者的格式都不正确,例如:

想要:CN=John Smith,OU=Users,OU=Organisation,OU=Tenants,DC=domain,DC=local

想要想要:domain.local/Tenants/Organisation/Users/John Smith

感谢任何帮助!

最终通过以下方式完成此工作:

public string getCanonicalName(string cDomain, string cUsername)
{
    string canonicalName = String.Empty;
    PrincipalContext ctx = new PrincipalContext(ContextType.Domain, cDomain);
    UserPrincipal user = UserPrincipal.FindByIdentity(ctx, cUsername);
    using (DirectoryEntry de = user.GetUnderlyingObject() as DirectoryEntry)
    {
          de.RefreshCache(new string[] { "canonicalName" });
          canonicalName = de.Properties["canonicalName"].Value as string;
    }
            
    return canonicalName;
}