need to parse csv file and email users new password

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 -To -From -subject "Your training password has been reset" -body "123456"

Who is Participating?
Raheman M. AbdulConnect With a Mentor Senior Infrastructure Support Analyst & Systems DeveloperCommented:
$path = "c:\temp\exampleuserlist.csv"
$csv = Import-csv -path $path
foreach($line in $csv)
{ Send-MailMessage -smtpserver -To $($line.smtpprimaryaddress) -From -subject "Training Environment Password Reset" -body "Your Training Password has been reset to $($line.newpassword)"  
mrdbeckerAuthor Commented:
Thanks Raheman! It worked like a charm!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.