Hi all,
Im trying to do a active directory lookup using powershell to find the users
email address from the
sAMAccountName's listed in a array or text file. At the moment I have got this far but not sure if its the best way and this way gets me more than just the
emailaddress@domain.com ###########################################################
cls
$SAMName = "users_sam_id"
$Searcher = New-Object DirectoryServices.DirectorySearcher
$Searcher.Searchroot ="LDAP://OU=XXXXXX,OU=XXXXX),DC=XXXXX,DC=XXX"
$searcher.filter = "(&(objectClass=user)(sAMAccountName= $SAMName))"
$userlist = "
mail"
$userlist | foreach {[void]$Searcher.Propertiestoload.Add($_)}
$userlist= $searcher.findall()
$results = $searcher.findall()
foreach ($result in $results){$result.properties}
$result.properties |ft value | out-file searchemail.txt
#############################################################
This works except it gives me more than just the
emailaddress@domain.com and doesnt read the sAMAccountName's from a text file.
Any help on this would be great.