返回LDAP管理器的displayName [英] Return the displayName of an LDAP manager

查看:108
本文介绍了返回LDAP管理器的displayName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些用于获取用户管理员的代码-我最初是为SharePoint网站编写代码的,但最近被要求使用VBA编写代码.

I have some code that I use to get the manager of a user - I originally wrote the code for a SharePoint site but was recently asked to write it using VBA.

Const SearchField = "DisplayName"
Const ReturnField = "manager"
Public Function MLookup(ByVal SearchString As String) As String
Application.ScreenUpdating = False
    Dim strDomain
    strDomain = GetObject("LDAP://rootDSE").Get("defaultNamingContext")
    Dim objConnection As ADODB.Connection
    Set objConnection = CreateObject("ADODB.Connection")
    objConnection.Open "Provider=ADsDSOObject;"
    Dim objCommand As ADODB.Command
    Set objCommand = CreateObject("ADODB.Command")
    objCommand.ActiveConnection = objConnection
    objCommand.CommandText = _
        "<LDAP://" & strDomain & ">;(&(objectCategory=User)" & _
        "(" & SearchField & "=" & SearchString & "));" & SearchField & "," & ReturnField & ";subtree"
    Dim objRecordSet As ADODB.Recordset
    Set objRecordSet = objCommand.Execute
    If objRecordSet.RecordCount = 0 Then
        MLookup = "Not Found"
    Else
        objMngr = objRecordSet.Fields(ReturnField)
        objMngr = Mid(objMngr, 4, InStr(1, objMngr, ",OU"))
        objMngr = Replace(objMngr, "\,", ",")
        objMngr = Left(objMngr, Len(objMngr) - 12)
        MLookup = Trim(objMngr)
    End If
    objConnection.Close
    Set objRecordSet = Nothing
    Set objCommand = Nothing
    Set objConnection = Nothing
Application.ScreenUpdating = True
End Function

这段代码工作正常 - 运行速度有点慢,因为我在家工作,但它完成了工作.我现在遇到了障碍.经理字段返回经理上的用户字符串,但是字符串是使用专有名称构建的-对于女士,这表示她们的娘家姓.该数据用于报告中,并激怒了一些人,因为这些数据在他们看来是不正确的.我想知道的是,是否可以将经理的返回字符串修改为该人的显示名称,而不是从经理字段中解析该名称?还是我创建第二个返回显示名称的函数的唯一解决方案(这会使我的响应时间加倍,并且在5000条记录上可能会太多)?

This code works fine - runs a little slow because I work from home but it gets the job done. I have run into a snag now though. The manager field returns the user string on the manager however the sting is built using the Distinguised Name - for ladies that means their maiden name. This data is used in a report and has ruffled some feathers because the data appears to them as incorrect. What I want to know is if there is a way to modify the return string of the manager to that person's display name instead of parsing the name out of the manager field? Or is my only solution to create a second function that returns display name (this would double my response time and on 5000 records that might be too much)?

推荐答案

简单(唯一)的答案是否".Manager字段(以及其他LDAP对象引用字段,例如 group 对象的多值 member 属性)仅包含distinguishedName,因为这就是在LDAP中标识对象的方式.但是,出于相同的原因,由distinguishedName进行的查找应该非常快.

The simple (and only) answer is no. The manager field (and other LDAP object reference fields, such as the multi-value member property of group objects) contain only the distinguishedName, because that's how objects are identified in LDAP. However, a lookup by distinguishedName should be extremely fast for the same reason.

我不确定,没有测试,但这可能有助于提高整个过程的速度,即对所有查询使用相同的命令和连接对象,而不是为每个实例重新创建它们.在保持方法分离性的同时实现此目的的一种方法是对方法采用可选的连接和/或命令参数.

Without testing I can't be sure, but it may help the speed of your overall process to use the same command and connection objects for all the queries, rather than recreating them for every instance. A way to do that while still maintaining the separation of the method would be to take optional connection and/or command parameters to the method.

最后,假设许多人拥有相同的经理,您可以使用字典缓存每个经理的显示名称,因此您只需为每个经理查找一次显示名称.

Finally, assuming many people will have the same managers, you could cache the display name for each manager using a Dictionary, so you only have to look up the display name once for each manager.

这篇关于返回LDAP管理器的displayName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆