How to search and replace a string in a file with cmd or PowerShell?

(get-content c:\1.txt) | foreach-object {$_ -replace "prod", "qa1"} | set-content c:\1.txt

The parentheses around Get-Content ensure that the Get operation is completed before the Set operation begins, without this the two functions would both try to access the file at the same time.