Recherche dans Active Directory
Bonjour,
J'ecris une fonction qui devrai renvoyer l'identifiant AdsPath d'un utilisateur dont on me fourni l'adresse email. Voici mon code :
Code:
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
}
} |
Je suis sur de l'existance des adresses email entrées en paramètres.
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.