remove backslash in a file with Powershell

时间:2016-04-15 15:19:27

标签: powershell

I cannot remove a string containing a backslash with Powershell

(Get-Content $file.fullName).replace('\\mystring', ') | Set-Content $file.fullName

It works if I had to remove 'mystring' only

(Get-Content $file.fullName).replace('mystring', ') | Set-Content $file.fullName

But with a backslash no. What's wrong?

1 个答案:

答案 0 :(得分:1)

使用反引号(`)来反转反斜杠。 你的命令看起来像

(Get-Content $file.fullName).replace('`\mystring', '') | Set-Content $file.fullName