I am trying to do find and replace in a file using following approach.
Function Find-Replace ($FileFullpath, $FindString, $ReplacementString) {
Get-Content $FileFullpath |
Foreach-Object {$_ -replace $FindString, $ReplacementString } |
Set-Content $FileFullpath
}
Find-Replace "c:program files (x86)MyProjweb.config" $OldServiceName $NewServiceName
But i am always getting error.
Set-Content : The process cannot access the file 'c:program files
(x86)MyProjweb.config' because it is being used by another process.
The file is not opened any where. I think Get-content is yet to release the file.
Why it happens ? How to do find and replace in the same file without issue?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…