我在PowerShell中尝试做一些非常简单的事情。
- Reading the contents of a file
- Manipulation some string
Saving the modified test back to the file
function Replace { $file = Get-Content C:\Path\File.cs $file | foreach {$_ -replace "document.getElementById", "$"} |out-file -filepath C:\Path\File.cs }
我也尝试过使用 Set-Content
。
但是每次都会出现未授权的异常。我可以看到 $file
里有文件内容,但在写入文件时出现了错误。
我该怎么解决这个问题?