Solved

need to parse csv file and email users new password

Posted on 2014-01-10
2
405 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 19

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 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