1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| Try
' Définition de l'emplacement de recherche
Dim monEmplacementRecherche As New DirectoryEntry("LDAP://monchemin")
' Instanciation d'un objet DirectorySearcher
Dim maRecherche As New DirectorySearcher(monEmplacementRecherche)
' dureeMax initisalisée à 45 secondes
'Dim dureeMax As New TimeSpan(0, 0, 45)
' Emplacement où la recherche doit être effectuée
' dans la hierarchie Active Directory
maRecherche.SearchRoot = monEmplacementRecherche
' Définition du Scope de la recherche, ici le conteneur
' seulement et tous ses "sous conteneur"
maRecherche.SearchScope = SearchScope.OneLevel
' Filtre uniquement les objets de type "organizationalUnit"
maRecherche.Filter = "(objectClass=organizationalUnit)"
' Détermination de la propriété à récupérer lors de la recherche
maRecherche.PropertiesToLoad.Add("name")
' Durée maximum de la recherche
'maRecherche.ServerTimeLimit = dureeMax
' Fixe le nombre maximum d'objets retournés
' maRecherche.SizeLimit = 1500
Dim uneOU As DirectoryServices.SearchResult
' Récupération du 'sAMAccountName' des utilisateurs récupérés
For Each uneOU In maRecherche.FindAll()
'DtListSite.Rows.Add(uneOU.GetDirectoryEntry.Properties.Item("name").Value.ToString, uneOU.GetDirectoryEntry.Properties.Item("description").Value)
Console.WriteLine(uneOU.GetDirectoryEntry.Properties.Item("name").Value.ToString)
Console.WriteLine(uneOU.GetDirectoryEntry.Properties.Item("description").Value.ToString)
Next
monEmplacementRecherche.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try |
Partager