ドメインの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
結果をどこかにキャッシュし、特定のスケジュールでキャッシュを無効にすることも、キャッシュを無効にする特定の要求に基づいてキャッシュを無効にすることもできます。その後、情報を取得する必要があるときは、キャッシュから読み取ります。 –
ユーザーのフルリストを読み取らずにカウントを行うことなく、OUのユーザーカウントを取得する方法はありますか? ADの各OUからすべてのユーザーを読み取ることは、永遠に続く部分です。 – JoshF