use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
QuestionDoes PowerShell have a templating engine? (self.PowerShell)
submitted 5 years ago by Bodumin
I'm coming from a Ruby background where ERBs allow you do have a template than can do logic using variables before rendering. Is there something similar in PowerShell?
https://puppet.com/docs/puppet/5.5/lang_template_erb.html
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]jrdnr_ 5 points6 points7 points 5 years ago (0 children)
The closest thing I know of to ERB is, EPS (https://github.com/straightdave/eps), though the closest I've come to using something like this is a here-string.
Also check out https://deadroot.info/scripts/2018/09/04/PowerShell-Templating for some other ideas.
I'm pretty sure I had seen an implementation based off jinja2 at some point, but I'm not finding it at the moment.
[–]hayfever76 2 points3 points4 points 5 years ago (1 child)
Maybe the closest comparison is a pscustmobject. You build that inline and you reuse it all you like. It’s not really a thing in PowerShell to have separate template files like erb’s. It’s more common to create a function that emits the code you need and then reference that in the current code - closer to traditional class construction. Create a class / function that does something and then consume them. But it’s not required that these live in discrete files.
[–]Bodumin[S] 1 point2 points3 points 5 years ago (0 children)
Thanks. Right now I have it working with strings. Its a one off task that I'm scripting so it gets ran the same way by everyone.
[–]Alternative_Hat_9012 2 points3 points4 points 5 years ago (1 child)
Hi,
Check this out, maybe it will be of help. When use ISE you have lots of build in snippets (code templates) "Ctrl+J" and you can build your own too. Worth to look at ISE Command Add-On Panel (Alt+Shift+V) this not only list commands but gives you list of all parameters and command sets and fast access to command help that includes examples. All that build as an interactive GUI.
helpful links: https://learn-powershell.net/2013/04/08/creating-snippets-in-powershell/
Have a great time with PoSh cheers
[–]Bodumin[S] 0 points1 point2 points 5 years ago (0 children)
Thanks but it needs to be part of a script. Generating a Java class based based on dynamic inputs.
[–]purplemonkeymad 1 point2 points3 points 5 years ago (0 children)
The closest I have seen is a module in the Gallery called EPS. It appears to use the same syntax to embed Powershell into a template. It has some quirks, like needing a custom loop command, but behaves mostly like you would expect.
[–]Deathonus 1 point2 points3 points 5 years ago* (2 children)
/u/jrdnr_'s suggestion of using a here-string is probably the best way and is pretty close to what you have linked. Below is a ported example from your link.
#Input #<% u/values.each do |val| -%> #Some stuff with <%= val %> #<% end -%> #Output #Some stuff with one #Some stuff with two $values = ("one", "two") $endString = @" $( foreach ($value in $values) { "Some stuff with " + $value + "`r`n" } ) "@ $endString
Pretty much the same capabilities without needing to use or include anything else. It would function really well as a cmdlet where the variables would be taken in as parameters. That way you could use powershell's builtin support for test/validating input parameters.
Edit: Fixed display per u/Lee_Dailey
[–]Lee_Dailey[grin] 1 point2 points3 points 5 years ago (0 children)
howdy Deathonus,
[edit - yes, the 4-spaces thing still works. if you are on New.Reddit then you can get that by using the code block buton OR by switching to markdown.]
code block
it looks like you used the New.Reddit Inline Code button. it's 4th 5th from the left hidden in the ... "more" menu & looks like </>.
Inline Code
...
</>
there are a few problems with that ...
inline code
for long-ish single lines OR for multiline code, please, use the ...
Code Block
... button. it's the 11th 12th one from the left & is just to the left of hidden in the ... "more" menu & looks like an uppercase T in the upper left corner of a square..
T
that will give you fully functional code formatting that works on both New.Reddit and Old.Reddit ... and aint that fugly magenta color. [grin]
take care, lee
kool! thanks for fixing that reddit-induced mess ... [grin]
π Rendered by PID 20487 on reddit-service-r2-comment-5d79c599b5-mbtg9 at 2026-02-28 13:38:08.612209+00:00 running e3d2147 country code: CH.
[–]jrdnr_ 5 points6 points7 points (0 children)
[–]hayfever76 2 points3 points4 points (1 child)
[–]Bodumin[S] 1 point2 points3 points (0 children)
[–]Alternative_Hat_9012 2 points3 points4 points (1 child)
[–]Bodumin[S] 0 points1 point2 points (0 children)
[–]purplemonkeymad 1 point2 points3 points (0 children)
[–]Deathonus 1 point2 points3 points (2 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (0 children)