Seems I searched for the correct combination of this, and though others are out there they are missing a closing bracket, was incomplete, or left things to be desired. Easiest way I could do this is by following the below process:

File with email addresses you need names for:

emailaddy.csv =

email
james@email.com
jerry@email.com
rick@email.com
jose@email.com


foreach($user in (get-content c:\users\james\desktop\emailaddy.csv)){get-aduser -filter {emailaddress -eq $user} |select -property samaccountname, userprincipalname, name}

Make sure you update your path for the CSV.

If you want to create another CSV from the output, make sure to use append, so the for loop can write to the file:

foreach($user in (get-content c:\users\james\desktop\emailaddy.csv)){get-aduser -filter {emailaddress -eq $user} |select -property samaccountname, userprincipalname, name | export-csv “c:\users\james\desktop\export.csv” –notypeinformation –append}

4 Spice ups

Does that work for you? What version of PowerShell are you running? I’m on v4 & it only returns the last name on the list. If I put them in proper CSV format, the Get-ADUser returns nothing & the foreach puts out the entire CSV string of all of them, commas & all.

I cheated on file paths. Working out of the local directory is easier than typing the full path.

I used my own Users’ addresses, not yours.

The input file you’re showing isn’t a CSV. It doesn’t matter if you put them on separate lines in a .TXT.

If I just do the foreach

foreach ($user in (get-content .\emailaddy.txt)){$user}

it dumps the file as entered. If I add the Get-ADUser, the only thing I get is the last one on the list:

foreach ($user in (get-content .\emailaddy.txt)){Get-ADUser -Filter {EmailAddress -eq $user}}

Or:

foreach ($user in (get-content .\emailaddy.txt)){Get-ADUser -Filter {EmailAddress -eq $user} | fl }

Or EVEN:

foreach ($user in (get-content .\emailaddy.txt)){Get-ADUser -Properties SamAccountName, UserPrincipalName, Name, EmailAddress -Filter 'EmailAddress -eq $user'}

If I leave off the -Filter on Get-ADUser, it prompts me for Filter: once for each entry, which is even more weird. The weirdest part of all is that last line, which dumps a lot more than the -Properties I chose, but only for the last entry in the input file.

Does yours work?