• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 414
  • Last Modified:

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 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
mrdbecker
Asked:
mrdbecker
1 Solution
 
Raheman M. AbdulCommented:
$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
 
mrdbeckerAuthor Commented:
Thanks Raheman! It worked like a charm!
0

Featured Post

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now