How can I replace every occurrence of a String in a file with PowerShell? - Stack Overflow

PHOTO EMBED

Mon Nov 04 2024 01:00:32 GMT+0000 (Coordinated Universal Time)

Saved by @baamn

function Replace-AllStringsInFile($SearchString,$ReplaceString,$FullPathToFile)
{
    $content = [System.IO.File]::ReadAllText("$FullPathToFile").Replace("$SearchString","$ReplaceString")
    [System.IO.File]::WriteAllText("$FullPathToFile", $content)
}
content_copyCOPY

https://stackoverflow.com/questions/17144355/how-can-i-replace-every-occurrence-of-a-string-in-a-file-with-powershell