PowerShell locking File....

Posted by Ben on Stack Overflow See other posts from Stack Overflow or by Ben
Published on 2010-06-16T22:37:16Z Indexed on 2010/06/16 22:42 UTC
Read the original article Hit count: 309

Filed under:

I am trying to do something very simple in powershell

  1. Reading the contents of a file
  2. Manipulation some string
  3. 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 }

I have tried Set-Content as well.

I always get unautorized exception. I can see the $file has the file content, error is coming while writing the file.

Any help is appreciated.

Ben

© Stack Overflow or respective owner

Related posts about powershell