This is probably caused by the Get-Content cmdlet, which gets a read lock and Out-File , which tries to get its write lock. A similar question: Powershell: how do you read and write I / O in one pipeline?
So the solution would be:
${C:\Path\File.cs} = ${C:\Path\File.cs} | foreach {$_ -replace "document.getElementById", '$'} ${C:\Path\File.cs} = Get-Content C:\Path\File.cs | foreach {$_ -replace "document.getElementById", '$'} $content = Get-Content C:\Path\File.cs | foreach {$_ -replace "document.getElementById", '$'} $content | Set-Content C:\Path\File.cs
Basically, you need to buffer the contents of the file so that the file can be closed ( Get-Content for reading), and after that the buffer should be flushed to the file ( Set-Content , during which write lock is required).
stej
source share