我遇到了同样的问题,下面帖子中的方法比我自己的要快得多:
http://msdn.microsoft.com/en-us/library/ms180881(v=vs.80).aspx
...要回答您的问题,是的,好像您尝试在仍在循环中时直接使用以下内容处理条目:
If Not UserAccount.GetDirectoryEntry().Properties("sAMAccountName").Value Is Nothing Then sAMAccountName = UserAccount.Properties("sAMAccountName")(0).ToString()
...这对性能有很大影响,您可以通过将集合添加到循环内的 Dictionary 然后处理字典来解决此问题:
Dim searchResult As SearchResult
Dim dictLatestLogonDatesTemp As New Dictionary(Of String, Date)
SearchResults1 = mySearcher.FindAll()
For Each searchResult In SearchResults1
Dim propertyKey,sAMAccountName As String
Dim dteLastLogonDate As Date = Nothing
For Each propertyKey In searchResult.Properties.PropertyNames
Dim valueCollection As ResultPropertyValueCollection = searchResult.Properties(propertyKey)
For Each propertyValue As Object In valueCollection
If LCase(propertyKey) = LCase("sAMAccountName") Then sAMAccountName = propertyValue
If LCase(propertyKey) = LCase("lastLogon") Then dteLastLogonDate = Date.FromFileTime(propertyValue)
Next propertyValue
Next propertyKey
If sAMAccountName <> Nothing Then dictLatestLogonDatesTemp.Add(sAMAccountName, dteLastLogonDate)
Next searchResult
这有点限制,因为字典只有两个条目,但您可以用逗号分隔其他值或使用字典中的值字典:
Dim tempDictionary As Dictionary(Of String, Dictionary(Of String, String))
希望这对某人有帮助!