get ADUsers emails [SOLVED]

by lopyeg at 2013-01-09 06:10:36

Hey guys.

One task appeared upon me.

I need to get AD logins from the file and get their emails.
Then i want to send emails in PS to these addresses,

but cant to do this, because have a minimal expirience in powershell

can anybody help me, please!

i tried
Get-Content test_users.txt | Foreach-Object { get-aduser $_ }
in this way i get many strings

How can I obtain the list of emails?

Please write if you know.
by Infradeploy at 2013-01-09 06:40:39
An obvious question would be: What is the format of the input file?
What’s does the data look like?
by ps_gregg at 2013-01-09 06:55:23
If the AD logins in the test_users.txt file are one per line:


then this should get you going.

Get-Content test_users.txt | ForEach-Object {

$useremail = Get-ADUser $_ -Properties mail | select -ExpandProperty mail
Send-MailMessage -To $useremail -Subject “Test Subject” -Body “Test Body” -From “” -SmtpServer “

by lopyeg at 2013-01-09 06:56:38

i just did it))) first command in my life))) like this
Get-Content test_users.txt | Foreach-Object { (get-aduser $_ -Properties mail).mail }
and it is works
now i will try to send emails to this users

thanks for help
by RichardSiddaway at 2013-01-09 12:17:33
The Send-MailMessage cmdlet can help you with that
by lopyeg at 2013-01-17 06:39:27
hello guys
does anybody know how to send via Send-MailMessage without authentication ?
i started PS as lopyeg user and i can send messages only -from
and i want to send -from
by lopyeg at 2013-01-17 06:48:30
$smtp = new-object Net.Mail.SmtpClient(“”) #Dns name or IP
$smtp.Send(“”, “”, “PowerShell Email”, “This is a email from powershell”)