给定表示Active Directory中用户的GUID,如何使用它来确定可分辨名称?

Joh*_*bly 4 .net c# active-directory

给定一个代表Active Directory中用户的GUID,我如何使用它来使用C#确定用户的"专有名称"?

使用directoryEntry.Guid在我们的应用程序中先前检索GUID; MSDN链接

Rob*_*Rob 10

正如您已经明确指出GUID是您正在搜索的内容,请尝试以下操作:

using System;
using System.DirectoryServices.AccountManagement;

public static class DomainHelpers
{    
    public string GetDistinguishedName(string domain, string guid)
    {
        var context = new PrincipalContext(ContextType.Domain, domain); 
        var userPrincipal  = UserPrincipal.FindByIdentity(context, IdentityType.Guid, guid);

        return userPrincipal.DistinguishedName;
    }
}
Run Code Online (Sandbox Code Playgroud)

我用过这个,IdentityType.Name所以不能确定它会起作用IdentityType.Guid,但值得一试.