Skip to content

Instantly share code, notes, and snippets.

@bricelam
Created August 8, 2014 01:21
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bricelam/a5debdbfc495eb7b116c to your computer and use it in GitHub Desktop.
Save bricelam/a5debdbfc495eb7b116c to your computer and use it in GitHub Desktop.
A simple token-replacement template engine for PowerShell
function Merge-Tokens($template, $tokens)
{
return [regex]::Replace(
$template,
'\$(?<tokenName>\w+)\$',
{
param($match)
$tokenName = $match.Groups['tokenName'].Value
return $tokens[$tokenName]
})
}
@bricelam
Copy link
Author

@craibuc Awesome. I love the ValueFromPipeline enhancement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment