Solved

need to parse csv file and email users new password

Posted on 2014-01-10
2
399 Views
Last Modified: 2014-01-13
Good Day,
I have a task to reset training users passwords to a random password and email each person their new password. I have the reset password script working. I just have an issue with the csv file for the email script. The format would be smtpprimaryaddress, newrandompassword in the csv.

How can I get powershell to look at each smtpprimaryaddress and email the corresponding new random password to each user.

I have a one liner that works but I'm not sure how to use variables for the rest.

Send-MailMessage -smtpserver 10.10.10.20 -To user01@domain.com -From admin@domain.com -subject "Your training password has been reset" -body "123456"

Thanks!
David
emailuser-notworking.txt
exampleuserlist.csv
0
Comment
Question by:mrdbecker
2 Comments
 
LVL 18

Accepted Solution

by:
Raheman M. Abdul earned 500 total points
ID: 39772688
$path = "c:\temp\exampleuserlist.csv"
$csv = Import-csv -path $path
foreach($line in $csv)
{
if($($line.smtpprimaryaddress))
{ Send-MailMessage -smtpserver 10.10.10.20 -To $($line.smtpprimaryaddress) -From admin@domain.com -subject "Training Environment Password Reset" -body "Your Training Password has been reset to $($line.newpassword)"  
}
}
0
 

Author Closing Comment

by:mrdbecker
ID: 39776966
Thanks Raheman! It worked like a charm!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now