Basic PowerShell Script Issue: “Expressions are only allowed as the first element of a pipeline”

后端 未结 2 1143
情深已故
情深已故 2021-01-17 21:11

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), i

2条回答
  •  死守一世寂寞
    2021-01-17 21:44

    I guess it is because after first pipe you are not processing each result. so the right one will be according to me :

    (Get-Content C:\file1.txt) | %{$_ -replace "this:text", "withthis:text"} | Set-Content C:\file2.txt
    

提交回复
热议问题