Powershell to loop thru CSV, populate variables in HTM file and email the person

Use Powershell to read an HTM file, import csv and for each csv record  replace variables in the HTM file

$Level3List = Import-Csv -Path 'C:\Users\usera\Downloads\List - Copy.csv'
$file = Get-Content -Path 'C:\Users\usera\Downloads\Confirmation.htm'

Foreach ($user in $Level3List)
{

$fullname = $user.cust_lname + ', ' + $user.cust_fname

$email = $user.Email
$accesscode = $user.access_code
$password = $user.password
    





}

Open in new window


In the file there are 4 areas that will be dynamic for the targeted recipient.  I am using {0} = $fullname, {1} = $accesscode and {2}=$password as the dynamic variable I want to have replaced
 color:black'>{0}<!----This is one of the Variables---><o:p></o:p></span></p>
color:black'>$fullname<o:p></o:p></span></p>
color:black'>{1}<!----This is one of the Variables---><o:p></o:p></span></p>
color:black'>$accesscode<o:p></o:p></span></p>
color:black'>{2}<!----This is one of the Variables---><o:p></o:p></span></p>
color:black'>$password<o:p></o:p></span></p>
Conferencing-Confirmation.htm
LVL 26
yo_beeDirector of Information TechnologyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yo_beeDirector of Information TechnologyAuthor Commented:
0
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
This would work (attached)

change txt to ps1 and run it like:
bee.ps1 -CsvFile "filepath"

(Also change line  15 to save the html files into the directory in there  [Parameter(Mandatory=$false,Position=3)]$targetpath ="E:\Libs\Desktop\bee\")
bee.txt
test.csv
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yo_beeDirector of Information TechnologyAuthor Commented:
Thanks Jose.
This worked for the replacement.  I will not work this into a loop to send the emails.
0
What were the top attacks of Q1 2018?

The Threat Lab team analyzes data from WatchGuard’s Firebox Feed, internal and partner threat intelligence, and a research honeynet, to provide insightful analysis about the top threats on the Internet. Check out our Q1 2018 report for smart, practical security advice today!

yo_beeDirector of Information TechnologyAuthor Commented:
This solution worked perfectly
0
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
Yeah just needed to add the Send-mail cmdlet at the end and give it the $file variable at the end so you can actually do the email part (to,subject,attachment,server and from) are the required values for the Send-mail.
1
yo_beeDirector of Information TechnologyAuthor Commented:
Worked like a charm
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

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.