Author Posts

January 10, 2017 at 1:38 pm

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,

January 10, 2017 at 2:26 pm

The code you posted doesn't output anything. You are assigning the results to a variable, but you never display that variable.

January 10, 2017 at 2:28 pm

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   
}

January 10, 2017 at 3:09 pm

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  
}

January 10, 2017 at 3:24 pm

So your text file might be the problem. Can you post a few lines of it here? But you should obfuscate sensitive information.

January 10, 2017 at 4:22 pm

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  
}

January 10, 2017 at 4:30 pm

same as before, doesn't display $Get

January 10, 2017 at 4:33 pm

hmmm ... I tried it and it's been working for me.

January 10, 2017 at 4:34 pm

found the problem, I had some "white spaces"

January 10, 2017 at 8:40 pm

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