Created
June 26, 2023 06:20
-
-
Save peterneave/f49bb26f8718e72dc07a1b4336fddf2c to your computer and use it in GitHub Desktop.
Multi Search and Replace with Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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