Skip to content

Instantly share code, notes, and snippets.

@auberginehill
Last active October 30, 2017 11:05
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 auberginehill/56d27ded52aacdd2f123c71d2a3fc0d1 to your computer and use it in GitHub Desktop.
Save auberginehill/56d27ded52aacdd2f123c71d2a3fc0d1 to your computer and use it in GitHub Desktop.
A code snippet, which replaces every occurrence of a string in a file with PowerShell
<#
Replace-String.ps1
#>
# Description: A code snippet, which replaces every occurrence of a string in a file with PowerShell
# Credit: rominator007: "How can I replace every occurrence of a String in a file with PowerShell?"
# Source: https://stackoverflow.com/questions/17144355/how-can-i-replace-every-occurrence-of-a-string-in-a-file-with-powershell?rq=1
$content = [System.IO.File]::ReadAllText("C:\Temp\example.txt").Replace("OldString","NewValue")
[System.IO.File]::WriteAllText("C:\Temp\example.txt", $content)
# www: https://gist.github.com/auberginehill/56d27ded52aacdd2f123c71d2a3fc0d1
# Short URL: http://tinyurl.com/ybrrgcnr
@auberginehill
Copy link
Author

[reserved]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment