Page 1 of 1

Populating Variables in External Text File

Posted: Sun Apr 15, 2018 7:18 pm
by pfgustafsson
Product, version and build: PowerShell Studio v5.5.150
32 or 64 bit version of product: 64 bit
Operating system: Win 10
32 or 64 bit OS: 64 Bit

*** Please add details and screenshots as needed below. ***

DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

Here's a question I had after reading the blog post on storing powershell variables within an external text file.
https://www.sapien.com/blog/2018/03/22/ ... nal-files/

After the reading the post, I was also working on a project where I wanted to do the reverse of what the article was talking about and have variables within a text file grab variable values from within the script.

Here’s the scenerio:
I have a list of new mailbox accounts and want to inform all the users of their new email address and credentials (sent to their old email address). I want to utilize a ‘form style’ text document with html formatting for the -BodyAsHtml switch in the Send-MailMessage cmdlet and push variable values into the body of the message. I can successfully include the html formatted message in the body of the message however, none of the variables get populated. There must be away to read the message body first and inject the variable values before sending the message. Question is, how?

Any thoughts?

Re: Populating Variables in External Text File

Posted: Mon Apr 16, 2018 7:01 am
by Alexander Riedel
[Topic moved by moderator]

Re: Populating Variables in External Text File

Posted: Mon Apr 16, 2018 7:24 am
by jvierra
Example:

Code: Select all

$body = @'
<pre>
    Dear  {0},
     Your free gift of {1} for being a dear customer
     has been shipped on {2}
<\pre>
'@
$body -f 'Jane Dough', 'vanilla cake', '12/31/2031'
https://blogs.technet.microsoft.com/hey ... owershell/

The "-f" operator is the string formatter operator and works as a "sprintf" function.