On 3/25/2010 2:13 PM, Dan Holmes wrote:
> i am trying to replace values in files. I get this "in use" message.
> Is this because the gc command still has the file open? How do others do
> this?
>
> PS D:\Sandbox> dir *.sql | %{$fn = $_.name ;gc $_.name } | % {$_
> -replace "SharedAgencyID", "CoordinatedAgencyID" }|sc $fn -Force
> Get-Content : The process cannot access the file 'D:\Sandbox\DM73427 -
> Coordination trips and billing\TripCoordinationListOffered.sql' because
> it is being used
> by another process.
> At line:1 char:33
> + dir *.sql | %{$fn = $_.name ;gc <<<< $_.name } | % {$_ -replace
> "SharedAgencyID", "CoordinatedAgencyID" }|sc $fn -Force
> + CategoryInfo : ReadError: (D:\Sandbox\DM73...ListOffered.sql:String)
> [Get-Content], IOException
> + FullyQualifiedErrorId :
> GetContentReaderIOError,Microsoft.PowerShell.Commands.GetContentCommand Ok, it was powershell that had the file open. I exited that session and started a new one. When i issued the command
this time.
PS D:\Sandbox\DM73427 - Coordination trips and billing> dir *.sql | %{$fn = $_.fullname ;gc $_.fullname } | % {$_
-replace "SharedAgencyID", "CoordinatedAgencyID";} | sc $fn -force
Set-Content : Cannot bind argument to parameter 'Path' because it is null.
At line:1 char:115
+ dir *.sql | %{$fn = $_.fullname ;gc $_.fullname } | % {$_ -replace "SharedAgencyID", "CoordinatedAgencyID";} | sc
<<<< $fn -force
+ CategoryInfo : InvalidData: (

[Set-Content], ParameterBindingValidationException
+ FullyQualifiedErrorId :
ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SetContentCommand
Every subsequent time creates the error above.