I'm trying to write a simple script that reads a file, locates a string, replaces the string with another string, and stores all new file contents (with replaced string), in a new file. Here is what I'm using:
(Get-Content C:file1.txt) | {$_ -replace "this:text", "withthis:text"} | Set-Content C:file2.txt
The error I'm receiving is: "Expressions are only allowed as the first element of a pipeline"
I'm pretty sure this is because of the colon ":" character being in both the string I'm locating and replacing it with. I've tried escaping the colon character with "" and "`" characters, but I'm receiving the same errors. Does anyone know what's wrong with this?
Thanks for the help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…