Solved

need to parse csv file and email users new password

Posted on 2014-01-10
2
402 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 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

820 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