c#AD计算机帐户DN

时间:2013-02-08 03:46:12

标签: c#

如何使用主体

在c#中获取AD计算机帐户DN
public string GetcomputerExtededProperty(string fieldName)
    {
        try
        {
            ComputerPrincipal oGroupPrincipal = GetComputer();
            return GetProperty((DirectoryEntry)oGroupPrincipal.GetUnderlyingObject(), fieldName);

        }
        catch
        {
            return "";
        }
    } 

1 个答案:

答案 0 :(得分:1)

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

PrincipalContext oCtx = new PrincipalContext(ContextType.Domain);
ComputerPrincipal oPrincipal = ComputerPrincipal.FindByIdentity(oCtx, computerName);
string dn = oPrincipal.DistinguishedName;