Powershell Tip #139: Replace every occurence of a string in a file By powershellgu | November 18, 2018 0 Comment Tip: You can replace every occurence of a string in a file. PowerShell # Preview (Get-Content -Path C:\Demo\test.txt).Replace('12345', '56789') # Save (to overwrite the file) (Get-Content -Path C:\Demo\test.txt).Replace('56789', '12345') | Set-Content -Path C:\Demo\test.txt 12345 # Preview(Get-Content -Path C:\Demo\test.txt).Replace('12345', '56789') # Save (to overwrite the file)(Get-Content -Path C:\Demo\test.txt).Replace('56789', '12345') | Set-Content -Path C:\Demo\test.txt