Bonjour,
J'ecris une fonction qui devrai renvoyer l'identifiant AdsPath d'un utilisateur dont on me fourni l'adresse email. Voici mon code :
Je suis sur de l'existance des adresses email entrées en paramètres.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 function LookUpPath($Mail) { # Defining a filter that will narrow the search to our user $strFilter = "(&(objectClass=user)(mail=$Mail))" $objDomain = New-Object System.DirectoryServices.DirectoryEntry("LDAP://OU=Administrations,dc=example,dc=com") # Defining a search object $objSearcher = New-Object System.DirectoryServices.DirectorySearcher # Setting the search properties $objSearcher.SearchRoot = $objDomain $objSearcher.PageSize = 100 $objSearcher.Filter = $strFilter $objSearcher.SearchScope = "Subtree" $colProplist = "AdsPath","displayName" foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)} # Starting the search $colResults = $objSearcher.FindOne() # Free memory used to collect data from search $objSearcher.Dispose() # Stops function and returns Null value if found nothing if ($colResults -eq $Null) {Write-Host "Null value returned by function";return $Null} else { # Returning the stored property $objItem = $colResult.Properties Write-Host "Trouvé utilisateur :" + $objItem.displayName return $objItem.ADsPath } }
Mon problème est que ma recherche reçoit apparement un resultat (variable $colResult non nul) mais ma fonction ne retourne que des valeurs vide.
Merci d'avance pour toute aide.
Partager