-3

我如何使用主体在 c# 中获取 AD 计算机帐户 DN

public string GetcomputerExtededProperty(string fieldName)
    {
        try
        {
            ComputerPrincipal oGroupPrincipal = GetComputer();
            return GetProperty((DirectoryEntry)oGroupPrincipal.GetUnderlyingObject(), fieldName);

        }
        catch
        {
            return "";
        }
    } 
4

1 回答 1

1

不确定这是否是您要查找的内容,但您可以使用类的FindByIdentity方法和DistinguishedName属性ComputerPrincipal(在 System.DirectoryServices.AccountManagement命名空间和程序集中):

PrincipalContext oCtx = new PrincipalContext(ContextType.Domain);
ComputerPrincipal oPrincipal = ComputerPrincipal.FindByIdentity(oCtx, computerName);
string dn = oPrincipal.DistinguishedName;
于 2013-02-08T05:37:03.607 回答