Skip to content

Instantly share code, notes, and snippets.

@peterneave
Created June 26, 2023 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterneave/f49bb26f8718e72dc07a1b4336fddf2c to your computer and use it in GitHub Desktop.
Save peterneave/f49bb26f8718e72dc07a1b4336fddf2c to your computer and use it in GitHub Desktop.
Multi Search and Replace with Powershell
$Dictionary = @{
"key1" = "value1";
"key2" = "value2";
}
$sourceFilename = "template.txt"
$destinationFilename = "output.txt"
$delimStart = "<"
$delimEnd = ">"
$templateContent = Get-Content $sourceFilename
$Dictionary.Keys | ForEach-Object {
$templateContent = $templateContent -replace "$delimStart$_$delimEnd", ($Dictionary[$_])
}
$templateContent | Set-Content $destinationFilename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment