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 27
yo_beeDirector of Information TechnologyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Jose Gabriel Ortega CastroCEO Faru Bonon IT - EE Solution ExpertCommented:
Problem unclear

You need to clarify what is within the HTML file and its structure also what is within the CSV file, properties, and stuff we're not wizards or fortune tellers.
Jose Gabriel Ortega CastroCEO Faru Bonon IT - EE Solution ExpertCommented:
Problem unclear

Dynamic variables has any  name?
What's the content of the Csv  (so we can have the properties that you want to get updated in the CSV properties with the HTML file).
yo_beeDirector of Information TechnologyAuthor Commented:
I have updated the question.
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

yo_beeDirector of Information TechnologyAuthor Commented:
Jose Gabriel Ortega CastroCEO Faru Bonon IT - EE Solution ExpertCommented:
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

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.
yo_beeDirector of Information TechnologyAuthor Commented:
This solution worked perfectly
Jose Gabriel Ortega CastroCEO Faru Bonon IT - EE Solution ExpertCommented:
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.
yo_beeDirector of Information TechnologyAuthor Commented:
Worked like a charm
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.