I have a text file with some email addresses
$text = Get-Content 'C:\Users\tantony\Desktop\email.txt'
foreach ($emails in $text)
{
$Get = Get-ADUser -Filter {Emailaddress -like "$emails"}
}
But, when I run this, it’s not displaying anything. The emails I have in the list are valid exchange emails.
Thanks,
The code you posted doesn’t output anything. You are assigning the results to a variable, but you never display that variable.
Olaf
3
You should at least have the last user in your variable $Get. 
Try this:
$text = Get-Content ‘C:\Users\tantony\Desktop\email.txt’
foreach ($emails in $text)
{
Get-ADUser -Filter {Emailaddress -like “$emails”} -Properties Emailaddress
}
Thank you,
I tried that, but it still doesn’t display anything. It should be displaying $Get, but it’s not.
$text = Get-Content ‘C:\Users\tantony\Desktop\email.txt’
foreach ($emails in $text)
{
$Get = Get-ADUser -Filter {Emailaddress -like "$emails"} -Properties Emailaddress
$Get
}
Olaf
5
So your text file might be the problem. Can you post a few lines of it here? But you should obfuscate sensitive information.
Olaf
7
OK, try this:
$text = Get-Content 'C:\Users\tantony\Desktop\email.txt'
foreach ($emails in $text)
{
$Get = Get-ADUser -Filter {Emailaddress -like $emails} -Properties Emailaddress
$Get
}
same as before, doesn’t display $Get
Olaf
9
hmmm … I tried it and it’s been working for me.
found the problem, I had some “white spaces”
Don’t need to do this
$Get = Get-ADUser -Filter {Emailaddress -like $emails} -Properties Emailaddress
$Get
as
Get-ADUser -Filter {Emailaddress -like $emails} -Properties Emailaddress
will display the result