我可以很容易地从我们的域的AD获取OU的列表,但我只想用用户帐户来获取OU。仅显示包含用户帐户的Active Directory OU
我目前正在抓取OU的列表,然后通过每个列表获取用户列表和计数,但处理所有这些数据可能需要大约30秒。
我希望有一些更快的方法来完成相同的任务。
Public Sub GetActiveDirectoryOuList()
Dim de As DirectoryEntry = Nothing
Dim ds As DirectorySearcher = Nothing
Dim results As SearchResultCollection = Nothing
Try
de = New DirectoryEntry("LDAP://DC=csileasing,DC=com")
ds = New DirectorySearcher(de, "(objectClass=organizationalUnit)")
results = ds.FindAll
If results.Count = 0 Then Exit Try
For Each result As SearchResult In results
Dim count As Integer = GetUserCountForOU(result.Properties("distinguishedName")(0).ToString)
If count > 0 Then
Dim ou As New OrgUnitInfo
ou.DistinguisedName = result.Properties("distinguishedName")(0).ToString
ou.Name = result.Properties("name")(0).ToString
ou.UsersCount = count
adOrgUnitList.Add(ou)
End If
Next
Catch ex As Exception
'MessageBox.Show(ex.Message)
Finally
If ds IsNot Nothing Then ds.Dispose()
If de IsNot Nothing Then de.Dispose()
If results IsNot Nothing Then results.Dispose()
End Try
End Sub
您可以在某处缓存结果,并根据特定的计划或基于特定请求使缓存无效,从而使缓存失效。然后,当您需要获取信息时,请从缓存中读取。 –
是否有一种方法可以在不读取完整用户列表的情况下获取用户数量,然后进行计数? 从AD的每个OU中读取所有用户是永久性的部分。 – JoshF