我有一个Active Directory搜索程序,可以使用UserPrincipal对象获取用户的详细信息。我使用System.DirectoryServices和System.DirectoryServices.AccountManagement,它通过上下文访问AD。
但是,我还需要将用户的管理器作为一个单独的UserPrincipal对象。在这方面,最直接的方法是什么?
我试过以下几种方法,但不幸的是,演员们无法工作:
DirectoryEntry directoryEntry = (DirectoryEntry)userPrincipal.GetUnderlyingObject();
UserPrincipal manager = (UserPrincipal)directoryEntry.Properties["manager"][0];我希望在每个UserPrincipal对象中都会有一个名为UsersManager的UsersManager属性,但是我找不到它,所以我猜没有这样的东西。
谢谢!
发布于 2016-05-05 13:15:00
manager属性将为您提供经理帐户的可分辨名称,它只是一个字符串。因此,您必须使用该DN查找经理的帐户。
这可能有效(假设您已经有了一个context对象):
UserPrincipal manager = UserPrincipal.FindByIdentity(context, IdentityType.DistinguishedName, directoryEntry.Properties["manager"][0].ToString());https://stackoverflow.com/questions/37051534
复制相似问题