c#AD计算机帐户DN

本文关键字:DN 计算机 c#AD | 更新日期: 2023-09-27 17:58:30

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

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

c#AD计算机帐户DN

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

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