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

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

Using PowerShell, I want to replace all exact occurrences of [MYID] in a given file with MyValue. What is the easiest way to do so?

Answers

Use (V3 version):

(Get-Content c:	emp	est.txt).replace( [MYID] ,  MyValue ) | Set-Content c:	emp	est.txt

Or for V2:

(Get-Content c:	emp	est.txt) -replace  [MYID] ,  MyValue  | Set-Content c:	emp	est.txt

Source

License : cc by-sa 3.0

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

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils