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?
Populating Variables in External Text File
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- pfgustafsson
- Posts: 6
- Last visit: Tue Jan 02, 2024 10:41 am
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Populating Variables in External Text File
[Topic moved by moderator]
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Populating Variables in External Text File
Example:
https://blogs.technet.microsoft.com/hey ... owershell/
The "-f" operator is the string formatter operator and works as a "sprintf" function.
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'
The "-f" operator is the string formatter operator and works as a "sprintf" function.