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

PHOTO EMBED

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

Saved by @baamn

$FileName =''
$OldLine = ''
$NewLine = ''
$Drives = Get-PSDrive -PSProvider FileSystem
foreach ($Drive in $Drives) {
    Push-Location $Drive.Root
        Get-ChildItem -Filter "$FileName" -Recurse | ForEach { 
            (Get-Content $_.FullName).Replace($OldLine, $NewLine) | Out-File $_.FullName
        }
    Pop-Location
}
content_copyCOPY

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