【问题标题】:Very slow finding a user in a Group AD VBS [duplicate]在组 AD VBS 中查找用户非常慢 [重复]
【发布时间】:2021-02-05 21:08:12
【问题描述】:

当我尝试查找某个用户是否是某个组的成员时,需要的时间太长。是否可以过滤 LDAP 搜索的基本 DN?

这里是函数。

' *****************************************************
'This function checks if the given AD user is a member of the given group.
Function IsMember(domainName,userName,groupName)
   Set groupListD = CreateObject("Scripting.Dictionary")
   groupListD.CompareMode = 1
   ADSPath = domainName & "/" & userName

   Set objUser = GetObject("WinNT://" & ADSPath & ",user")
   For Each objGroup in objUser.Groups
       groupListD.Add objGroup.Name, "-"
   Next
   IsMember = CBool(groupListD.Exists(groupName))
   
End Function
' *****************************************************

谢谢

【问题讨论】:

标签: vbscript active-directory adsutil.vbs


【解决方案1】:

找到匹配组后,您无需遍历所有组,这应该会有所帮助:

Function IsMember(domainName, userName, groupName)
    Dim sADSPath
    Dim objUser
    Dim objGroup

    sADSPath = domainName & "/" & userName
    
    Set objUser = GetObject("WinNT://" & sADSPath & ",user")
   
    If objUser Is Nothing Then 
        IsMember = False
        Exit Function
    End If 

    For Each objGroup In objUser.Groups
        If StrComp(objGroup.Name, groupName, vbTextCompare) = 0 Then
            IsMember = True
            Exit Function
        End If
    Next
   
    IsMember = False
   
End Function

此外,无需创建组名并将其添加到字典中。

【讨论】:

  • 谢谢!如果您需要查找计算机是否是组的成员,您会怎么做?感谢您的帮助。
  • 您可以为此发布一个单独的问题,但这可能会回答您的问题或给您一些想法:Determine if computer is in AD group
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-18
  • 2017-12-06
  • 2017-08-23
  • 2015-12-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多