by lopyeg at 2013-01-09 06:10:36
Hey guys.by Infradeploy at 2013-01-09 06:40:39
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.
An obvious question would be: What is the format of the input file?by ps_gregg at 2013-01-09 06:55:23
What’s does the data look like?
If the AD logins in the test_users.txt file are one per line:by lopyeg at 2013-01-09 06:56:38
user1
user2
user3
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 "valid-email@domain.com" -SmtpServer "mailserver.domain.com"
}
txtby RichardSiddaway at 2013-01-09 12:17:33
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
The Send-MailMessage cmdlet can help you with thatby lopyeg at 2013-01-17 06:39:27
hello guysby lopyeg at 2013-01-17 06:48:30
and
does anybody know how to send via Send-MailMessage without authentication ?
i started PS as lopyeg user and i can send messages only -from lopyeg@domain.com
and i want to send -from monitoring@domain.com
$smtp = new-object Net.Mail.SmtpClient("mailrelay.yourdomain1.com") #Dns name or IP
$smtp.Send("myaccount@email.edu", "someone@gmail.com", "PowerShell Email", "This is a email from powershell")
bingo)