amateur amateur - 9 months ago 36
PowerShell Question

How can I replace every occurence of a String in a file with PowerShell?

Using PowerShell, I want to replace all exact occurrences of

in a given file with
. What is the easiest way to do so?


Use (V3 version):

(Get-Content c:\temp\test.txt).replace('[MYID]', 'MyValue') | Set-Content c:\temp\test.txt

Or for V2:

(Get-Content c:\temp\test.txt) -replace '\[MYID\]', 'MyValue' | Set-Content c:\temp\test.txt